lithium\data\collection\RecordSet::_set()
Implements
lithium\data\Collection::_set()
Sets item to passed data with the key from the query object or a given offset.
Due to behaviour changes in PHP 7.3 and above the internal array pointer of the
$_data
property might not be updated after setting a value by key. To preserve
the behavior the internal array pointer is updated manually using reset()
and
end()
.
Parameters
-
mixed
$data
-
integer
$offset
-
array
$options
Returns
mixed$data
Links
Source
protected function _set($data = null, $offset = null, $options = []) {
if ($model = $this->_model) {
$options += ['defaults' => false];
$data = !is_object($data) ? $model::create($data, $options) : $data;
$key = $model::key($data);
} else {
$key = $offset;
}
if (is_array($key)) {
$key = count($key) === 1 ? current($key) : null;
}
if ($key === null) {
return $this->_data[] = $data;
}
reset($this->_data);
$this->_data[$key] = $data;
end($this->_data);
return $data;
}