public function convertToTargetType($path, $value, $targetType = '')
    {
        $targetType = $targetType ?: $this->getType($path);
        $actualType = gettype($value);
        if ($actualType !== $targetType && $targetType !== 'NULL') {
            if ($this->isTypeConvertible($targetType, $actualType)) {
                switch ($targetType) {
                    case 'integer':
                        $value = (int)$value;
                        break;
                    case 'float':
                    case 'double':
                        $value = (float)$value;
                        break;
                    case 'boolean':
                        $value = (bool)$value;
                        break;
                    case 'string':
                        $value = (string)$value;
                        break;
                    default:
                        // We don't know any type conversion, so we better exit
                        throw new TypesAreNotConvertibleException(sprintf('Unknown target type "%s"', $targetType), 1477778705);
                }
            } else {
                // We cannot convert from or to non scalar types, so we better exit
                throw new TypesAreNotConvertibleException(sprintf('Cannot convert type from "%s" to "%s"', $actualType, $targetType), 1477778754);
            }
        }

        return $value;
    }
public function convertToTargetType($path, $value, $targetType = '')
    {
        $targetType = $targetType ?: $this->getType($path);
        $actualType = gettype($value);
        if ($actualType !== $targetType && $targetType !== 'NULL') {
            if ($this->isTypeConvertible($targetType, $actualType)) {
                switch ($targetType) {
                    case 'integer':
                        $value = (int)$value;
                        break;
                    case 'float':
                    case 'double':
                        $value = (float)$value;
                        break;
                    case 'boolean':
                        $value = (bool)$value;
                        break;
                    case 'string':
                        $value = (string)$value;
                        break;
                    default:
                        // We don't know any type conversion, so we better exit
                        throw new TypesAreNotConvertibleException(sprintf('Unknown target type "%s"', $targetType), 1477778705);
                }
            } else {
                // We cannot convert from or to non scalar types, so we better exit
                throw new TypesAreNotConvertibleException(sprintf('Cannot convert type from "%s" to "%s"', $actualType, $targetType), 1477778754);
            }
        }

        return $value;
    }
public function convertToTargetType ( $ path , $ value , $ targetType = '' ) { $ targetType = $ targetType ? : $ this -> getType ( $ path ) ; $ actualType = gettype ( $ value ) ; if ( $ actualType !== $ targetType && $ targetType !== 'NULL' ) { if ( $ this -> isTypeConvertible ( $ targetType , $ actualType ) ) { switch ( $ targetType ) { case 'integer' : $ value = ( int ) $ value ; break ; case 'float' : case 'double' : $ value = ( float ) $ value ; break ; case 'boolean' : $ value = ( bool ) $ value ; break ; case 'string' : $ value = ( string ) $ value ; break ; default : // We don't know any type conversion, so we better exit throw new TypesAreNotConvertibleException ( sprintf ( 'Unknown target type "%s"' , $ targetType ) , 1477778705 ) ; } } else { // We cannot convert from or to non scalar types, so we better exit throw new TypesAreNotConvertibleException ( sprintf ( 'Cannot convert type from "%s" to "%s"' , $ actualType , $ targetType ) , 1477778754 ) ; } } return $ value ; }
Convert a value to the type belonging to the given path

@param string $path
@param string $value
@param string $targetType
@throws TypesAreNotConvertibleException
@return bool|float|int|string
Convert a value to the type belonging to the given path