lithium\data\collection\DocumentSet::_set()
Implements
lithium\data\Collection::_set()
Helper method to normalize and set data.
Parameters
-
mixed
$data
-
null|integer|string
$offset
-
array
$options
Returns
mixedThe (potentially) cast data.
Source
protected function _set($data = null, $offset = null, $options = []) {
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;
}