/** * 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]; }
/** * @param mixed $body * @param mixed $parameters * @param mixed[] $headers * @param string $method * @param string $location * @param array $options */ public function __construct($body = null, $parameters = null, array $headers = null, $method = null, $location = null, $options = []) { $this->setBody($body); $this->setParameters($parameters); if (!is_null($headers)) { $this->setHeaders($headers); } $this->setMethod($method); $this->setLocation($location); $this->setOptions($options); parent::__construct(); }