Select::convertTo: Bitrix method

      
<?php 
//  Bitrix\Bizproc\BaseType\Select :: convertTo()
//  /dist/bitrix/modules/bizproc/lib/basetype/select.php:43

    
public static function convertTo(FieldType $fieldType$value$toTypeClass)
    {
        
/** @var Base $toTypeClass */
        
$type $toTypeClass::getType();
        
$options = static::getFieldOptions($fieldType);

        
$key $originalValue $value;
        if (
is_array($value))
        {
            foreach(
$value as $k => $v)
            {
                
$key $k;
                
$originalValue $v;
            }
        }
        elseif (isset(
$options[$key]))
        {
            
$originalValue $options[$value];
        }

        switch (
$type)
        {
            case 
FieldType::BOOL:
                
$value strtolower((string)$key);
                
$value in_array($value, array('y''yes''true''1')) ? 'Y' 'N';
                break;
            case 
FieldType::DOUBLE:
                
$value str_replace(' '''str_replace(',''.'$key));
                
$value = (float)$value;
                break;
            case 
FieldType::INT:
                
$value str_replace(' '''$key);
                
$value = (int)$value;
                break;
            case 
FieldType::STRING:
            case 
FieldType::TEXT:
                
$value = (string) $originalValue;
                break;
            case 
FieldType::SELECT:
                
$value = (string) $key;
                break;
            case 
FieldType::USER:
                
$value trim($key);
                if (
strpos($value'user_') === false
                    
&& strpos($value'group_') === false
                    
&& !preg_match('#^[0-9]+$#'$value)
                )
                {
                    
$value null;
                }
                break;
            default:
                
$value null;
        }

        return 
$value;
    }