public function _cast($name, $data, $options)
    {
        if ($data === null) {
            return;
        }
        if ($data instanceof Document) {
            return $data;
        }

        $class = ltrim($options['class'], '\\');

        $config = [
            'schema'    => $class === Document::class ? $this : null,
            'basePath'  => $options['basePath'],
            'exists'    => $options['exists'],
            'defaults'  => $options['defaults']
        ];
        if (isset($options['config'])){
            $config = Set::extend($config, $options['config']);
        }

        $column = isset($this->_columns[$name]) ? $this->_columns[$name] : [];
        if (!empty($column['format'])) {
            $data = $this->convert('cast', $column['format'], $data, $column, $config);
        }

        return $class::create($data ? $data : [], $config);
    }
public function _cast($name, $data, $options)
    {
        if ($data === null) {
            return;
        }
        if ($data instanceof Document) {
            return $data;
        }

        $class = ltrim($options['class'], '\\');

        $config = [
            'schema'    => $class === Document::class ? $this : null,
            'basePath'  => $options['basePath'],
            'exists'    => $options['exists'],
            'defaults'  => $options['defaults']
        ];
        if (isset($options['config'])){
            $config = Set::extend($config, $options['config']);
        }

        $column = isset($this->_columns[$name]) ? $this->_columns[$name] : [];
        if (!empty($column['format'])) {
            $data = $this->convert('cast', $column['format'], $data, $column, $config);
        }

        return $class::create($data ? $data : [], $config);
    }
public function _cast ( $ name , $ data , $ options ) { if ( $ data === null ) { return ; } if ( $ data instanceof Document ) { return $ data ; } $ class = ltrim ( $ options [ 'class' ] , '\\' ) ; $ config = [ 'schema' => $ class === Document :: class ? $ this : null , 'basePath' => $ options [ 'basePath' ] , 'exists' => $ options [ 'exists' ] , 'defaults' => $ options [ 'defaults' ] ] ; if ( isset ( $ options [ 'config' ] ) ) { $ config = Set :: extend ( $ config , $ options [ 'config' ] ) ; } $ column = isset ( $ this -> _columns [ $ name ] ) ? $ this -> _columns [ $ name ] : [ ] ; if ( ! empty ( $ column [ 'format' ] ) ) { $ data = $ this -> convert ( 'cast' , $ column [ 'format' ] , $ data , $ column , $ config ) ; } return $ class :: create ( $ data ? $ data : [ ] , $ config ) ; }
Casting helper for entities.

@param  string $name       The field name to cast.
@param  array  $data       Some data to cast.
@param  array  $options    Options for the casting.
@return mixed              The casted data.
Casting helper for entities .