/** * Converts attributes to specific dataobjects if configured to * * @param string $key * @return mixed|DataObjectInterface */ public function &getAttributeValue($key) { if (!count($this->objects) || !array_key_exists($key, $this->objects)) { return parent::getAttributeValue($key); } if (!isset($this->attributes[$key])) { $null = null; return $null; } $dataObjectClass = $this->objects[$key]; $dataObjectArray = false; if (substr($dataObjectClass, -2) === '[]') { $dataObjectClass = substr($dataObjectClass, 0, -2); $dataObjectArray = true; } if ($dataObjectArray) { if (is_array($this->attributes[$key])) { foreach ($this->attributes[$key] as &$item) { if (!is_a($item, $dataObjectClass)) { /** @var DataObjectInterface $item */ $item = new $dataObjectClass($item->toArray()); } } } unset($item); } else { if (!is_a($this->attributes[$key], $dataObjectClass)) { $this->attributes[$key] = new $dataObjectClass((array) $this->attributes[$key]); } } return $this->attributes[$key]; }