protected function castValue($value, $type)
    {
        if (isset($this->scalarMap[$type])) {
            $cast = $this->castToScalar($value, $this->scalarMap[$type]);

            return $cast == $value ? $cast : $value;
        }

        if (is_null($value)) {
            return null;
        }

        if (!is_array($value) && $type === 'array') {
            return (array) $value;
        }

        if (!is_object($value) && $type === 'object') {
            return (object) $value;
        }

        return $this->castToClass($value, $this->resolveNamespace($type));
    }
protected function castValue($value, $type)
    {
        if (isset($this->scalarMap[$type])) {
            $cast = $this->castToScalar($value, $this->scalarMap[$type]);

            return $cast == $value ? $cast : $value;
        }

        if (is_null($value)) {
            return null;
        }

        if (!is_array($value) && $type === 'array') {
            return (array) $value;
        }

        if (!is_object($value) && $type === 'object') {
            return (object) $value;
        }

        return $this->castToClass($value, $this->resolveNamespace($type));
    }
protected function castValue ( $ value , $ type ) { if ( isset ( $ this -> scalarMap [ $ type ] ) ) { $ cast = $ this -> castToScalar ( $ value , $ this -> scalarMap [ $ type ] ) ; return $ cast == $ value ? $ cast : $ value ; } if ( is_null ( $ value ) ) { return null ; } if ( ! is_array ( $ value ) && $ type === 'array' ) { return ( array ) $ value ; } if ( ! is_object ( $ value ) && $ type === 'object' ) { return ( object ) $ value ; } return $ this -> castToClass ( $ value , $ this -> resolveNamespace ( $ type ) ) ; }
Cast a value to the desired type non-destructively.

@param mixed  $value
@param string $type

@return mixed Cast value
Cast a value to the desired type non - destructively .