lithium\data\collection\DocumentSet::_set PHP Method

_set() protected method

Helper method to normalize and set data.
protected _set ( mixed $data = null, null | integer | string $offset = null, array $options = [] ) : mixed
$data mixed
$offset null | integer | string
$options array
return mixed The (potentially) cast data.
    protected function _set($data = null, $offset = null, $options = array())
    {
        if ($schema = $this->schema()) {
            $model = $this->_model;
            $pathKey = $this->_pathKey;
            $options = compact('model', 'pathKey') + $options;
            $data = !is_object($data) ? $schema->cast($this, $offset, $data, $options) : $data;
            $key = $model && $data instanceof Document ? $model::key($data) : $offset;
        } else {
            $key = $offset;
        }
        if (is_array($key)) {
            $key = count($key) === 1 ? current($key) : null;
        }
        if (is_object($key)) {
            $key = (string) $key;
        }
        if (is_object($data) && method_exists($data, 'assignTo')) {
            $data->assignTo($this);
        }
        $key !== null ? $this->_data[$key] = $data : ($this->_data[] = $data);
        if (isset($options['original']) && $options['original']) {
            $key !== null ? $this->_original[$key] = $data : ($this->_original[] = $data);
        }
        return $data;
    }