public function _castArray($name, $data, $options)
    {
        $options['type'] = isset($options['relation']) && $options['relation'] === 'hasManyThrough' ? 'through' : 'set';
        $class = ltrim($options['class'], '\\');
        $classes = $class::classes();
        $collection = $classes[$options['type']];

        if ($data instanceof $collection) {
            return $data;
        }

        $isThrough = $options['type'] === 'through';

        $isDocument = $class === Document::class;

        $config = [
            'schema'    => $isDocument ? $this : $class::definition(),
            'basePath'  => $isDocument ? $name : null,
            'meta'      => isset($options['meta']) ? $options['meta'] : [],
            '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 !== null) {
            $type = $column['format'];
            $data = $this->convert('cast', $type, $data, $column, $config);
        }

        if ($isThrough) {
            $config['parent'] = $options['parent'];
            $config['through'] = $options['through'];
            $config['using'] = $options['using'];
            $config['data'] = $data;
        } else {
            $config['data'] = $data ?: [];
        }
        return new $collection($config);
    }
public function _castArray($name, $data, $options)
    {
        $options['type'] = isset($options['relation']) && $options['relation'] === 'hasManyThrough' ? 'through' : 'set';
        $class = ltrim($options['class'], '\\');
        $classes = $class::classes();
        $collection = $classes[$options['type']];

        if ($data instanceof $collection) {
            return $data;
        }

        $isThrough = $options['type'] === 'through';

        $isDocument = $class === Document::class;

        $config = [
            'schema'    => $isDocument ? $this : $class::definition(),
            'basePath'  => $isDocument ? $name : null,
            'meta'      => isset($options['meta']) ? $options['meta'] : [],
            '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 !== null) {
            $type = $column['format'];
            $data = $this->convert('cast', $type, $data, $column, $config);
        }

        if ($isThrough) {
            $config['parent'] = $options['parent'];
            $config['through'] = $options['through'];
            $config['using'] = $options['using'];
            $config['data'] = $data;
        } else {
            $config['data'] = $data ?: [];
        }
        return new $collection($config);
    }
public function _castArray ( $ name , $ data , $ options ) { $ options [ 'type' ] = isset ( $ options [ 'relation' ] ) && $ options [ 'relation' ] === 'hasManyThrough' ? 'through' : 'set' ; $ class = ltrim ( $ options [ 'class' ] , '\\' ) ; $ classes = $ class :: classes ( ) ; $ collection = $ classes [ $ options [ 'type' ] ] ; if ( $ data instanceof $ collection ) { return $ data ; } $ isThrough = $ options [ 'type' ] === 'through' ; $ isDocument = $ class === Document :: class ; $ config = [ 'schema' => $ isDocument ? $ this : $ class :: definition ( ) , 'basePath' => $ isDocument ? $ name : null , 'meta' => isset ( $ options [ 'meta' ] ) ? $ options [ 'meta' ] : [ ] , '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 !== null ) { $ type = $ column [ 'format' ] ; $ data = $ this -> convert ( 'cast' , $ type , $ data , $ column , $ config ) ; } if ( $ isThrough ) { $ config [ 'parent' ] = $ options [ 'parent' ] ; $ config [ 'through' ] = $ options [ 'through' ] ; $ config [ 'using' ] = $ options [ 'using' ] ; $ config [ 'data' ] = $ data ; } else { $ config [ 'data' ] = $ data ? : [ ] ; } return new $ collection ( $ config ) ; }
Casting helper for arrays.

@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 arrays .