lithium\data\entity\Document::__get()
Overrides
lithium\data\Entity::__get()
PHP magic method used when accessing fields as document properties, i.e. $document->_id
.
Parameters
-
$name
The
field name, as specified with an object property.
Returns
mixedReturns the value of the field specified in $name
, and wraps complex data
types in sub-Document
objects.
Source
public function &__get($name) {
if (strpos($name, '.')) {
return $this->_getNested($name);
}
if (isset($this->_embedded[$name]) && !isset($this->_relationships[$name])) {
throw new RuntimeException("Not implemented.");
}
$result =& parent::__get($name);
if ($result !== null || array_key_exists($name, $this->_updated)) {
return $result;
}
if ($field = $this->schema($name)) {
if (isset($field['default'])) {
$this->set([$name => $field['default']]);
return $this->_updated[$name];
}
if (isset($field['array']) && $field['array'] && ($model = $this->_model)) {
$this->_updated[$name] = $model::create([], [
'class' => 'set',
'schema' => $this->schema(),
'pathKey' => $this->_pathKey ? $this->_pathKey . '.' . $name : $name,
'parent' => $this,
'model' => $this->_model,
'defaults' => false
]);
return $this->_updated[$name];
}
}
$null = null;
return $null;
}