StringType :: convertTo: Bitrix method

      
<?php 
//  Bitrix\Bizproc\BaseType\StringType :: convertTo()
//  /dist/bitrix/modules/bizproc/lib/basetype/stringtype.php:44

    
public static function convertTo(FieldType $fieldType$value$toTypeClass)
    {
        
/** @var Base $toTypeClass */
        
$type $toTypeClass::getType();
        switch (
$type)
        {
            case 
FieldType::BOOL:
                
$value strtolower((string)$value);
                
$value in_array($value, array('y''yes''true''1')) ? 'Y' 'N';
                break;
            case 
FieldType::DATE:
            case 
FieldType::DATETIME:
                
$value = (string) $value;
                if (
$value)
                {
                    
$format = ($type == FieldType::DATE) ? \FORMAT_DATE : \FORMAT_DATETIME;
                    if (\
CheckDateTime($value$format))
                    {
                        
$value date(Main\Type\Date::convertFormatToPhp($format), \CBPHelper::makeTimestamp($value$format));
                    }
                    else
                    {
                        
$value date(Main\Type\Date::convertFormatToPhp($format), strtotime($value));
                    }
                }
                break;
            case 
FieldType::DOUBLE:
                
$value str_replace(' '''str_replace(',''.'$value));
                
$value = (float)$value;
                break;
            case 
FieldType::INT:
                
$value str_replace(' '''$value);
                
$value = (int)$value;
                break;
            case 
FieldType::STRING:
            case 
FieldType::TEXT:
                
$value = (string) $value;
                break;
            case 
FieldType::USER:
                
$value trim($value);
                if (
strpos($value'user_') === false
                    
&& strpos($value'group_') === false
                    
&& !preg_match('#^[0-9]+$#'$value)
                )
                {
                    
$value null;
                }
                break;
            default:
                
$value null;
        }

        return 
$value;
    }