public static function castFromString($type, $value, $php_type)
    {
        //Here should maybe handle locale specific tz overrides in the future.
        $timezone = null;

        switch ($type) {

            case self::PROPERTY_TYPE_INT:
                return (int) $value;

            case self::PROPERTY_TYPE_FLOAT:
                return (float) $value;

            case self::PROPERTY_TYPE_BOOLEAN:
                return in_array(strtolower($value), ['true', '1', 'yes'], true);

            /** @noinspection PhpMissingBreakStatementInspection */
            case self::PROPERTY_TYPE_TIMESTAMP:
                $timezone = new \DateTimeZone('UTC');

                // no break
            case self::PROPERTY_TYPE_DATE:
                if (preg_match('/Date\\((?<timestamp>[0-9\\+\\.]+)\\)/', $value, $matches)) { //to catch stupid .net date serialisation
                    $value = $matches['timestamp'];
                }

                return new \DateTime($value, $timezone);

            case self::PROPERTY_TYPE_OBJECT:
                $php_type = sprintf('\\XeroPHP\\Models\\%s', $php_type);
                /** @var self $instance */
                $instance = new $php_type();
                $instance->fromStringArray($value);

                return $instance;

            default:
                if (is_scalar($value)) {
                    return (string) $value;
                }

                return (object) $value;
        }
    }
public static function castFromString($type, $value, $php_type)
    {
        //Here should maybe handle locale specific tz overrides in the future.
        $timezone = null;

        switch ($type) {

            case self::PROPERTY_TYPE_INT:
                return (int) $value;

            case self::PROPERTY_TYPE_FLOAT:
                return (float) $value;

            case self::PROPERTY_TYPE_BOOLEAN:
                return in_array(strtolower($value), ['true', '1', 'yes'], true);

            /** @noinspection PhpMissingBreakStatementInspection */
            case self::PROPERTY_TYPE_TIMESTAMP:
                $timezone = new \DateTimeZone('UTC');

                // no break
            case self::PROPERTY_TYPE_DATE:
                if (preg_match('/Date\\((?<timestamp>[0-9\\+\\.]+)\\)/', $value, $matches)) { //to catch stupid .net date serialisation
                    $value = $matches['timestamp'];
                }

                return new \DateTime($value, $timezone);

            case self::PROPERTY_TYPE_OBJECT:
                $php_type = sprintf('\\XeroPHP\\Models\\%s', $php_type);
                /** @var self $instance */
                $instance = new $php_type();
                $instance->fromStringArray($value);

                return $instance;

            default:
                if (is_scalar($value)) {
                    return (string) $value;
                }

                return (object) $value;
        }
    }
public static function castFromString ( $ type , $ value , $ php_type ) { //Here should maybe handle locale specific tz overrides in the future. $ timezone = null ; switch ( $ type ) { case self :: PROPERTY_TYPE_INT : return ( int ) $ value ; case self :: PROPERTY_TYPE_FLOAT : return ( float ) $ value ; case self :: PROPERTY_TYPE_BOOLEAN : return in_array ( strtolower ( $ value ) , [ 'true' , '1' , 'yes' ] , true ) ; /** @noinspection PhpMissingBreakStatementInspection */ case self :: PROPERTY_TYPE_TIMESTAMP : $ timezone = new \ DateTimeZone ( 'UTC' ) ; // no break case self :: PROPERTY_TYPE_DATE : if ( preg_match ( '/Date\\((?<timestamp>[0-9\\+\\.]+)\\)/' , $ value , $ matches ) ) { //to catch stupid .net date serialisation $ value = $ matches [ 'timestamp' ] ; } return new \ DateTime ( $ value , $ timezone ) ; case self :: PROPERTY_TYPE_OBJECT : $ php_type = sprintf ( '\\XeroPHP\\Models\\%s' , $ php_type ) ; /** @var self $instance */ $ instance = new $ php_type ( ) ; $ instance -> fromStringArray ( $ value ) ; return $ instance ; default : if ( is_scalar ( $ value ) ) { return ( string ) $ value ; } return ( object ) $ value ; } }
Cast the values to PHP types.

@param $type
@param $value
@param $php_type
@return bool|\DateTimeInterface|float|int|string
Cast the values to PHP types .