Create relationship object.
public createRelationshipObject ( string $name, object | array | null $data, \Neomerx\JsonApi\Contracts\Schema\LinkInterface>\array |
||
$name | string | |
$data | object | array | null | |
$links | \Neomerx\JsonApi\Contracts\Schema\LinkInterface>\array | |
$meta | mixed | |
$isShowData | boolean | |
$isRoot | boolean | |
return | Neomerx\JsonApi\Contracts\Schema\RelationshipObjectInterface |
/** * @inheritdoc */ public function parse($data) { $this->stack = $this->stackFactory->createStack(); $rootFrame = $this->stack->push(); $rootFrame->setRelationship($this->schemaFactory->createRelationshipObject(null, $data, [], null, true, true)); foreach ($this->parseData() as $parseReply) { (yield $parseReply); } $this->stack = null; }
/** * @param object $resource * @param string $name * @param array $desc * * @return RelationshipObjectInterface */ protected function createRelationshipObject($resource, $name, array $desc) { $data = $this->getValue($desc, self::DATA); $meta = $this->getValue($desc, self::META, null); $isShowSelf = $this->getValue($desc, self::SHOW_SELF, false) === true; $isShowRelated = $this->getValue($desc, self::SHOW_RELATED, false) === true; $isShowData = $this->getValue($desc, self::SHOW_DATA, array_key_exists(self::DATA, $desc)) === true; $links = $this->readLinks($resource, $name, $desc, $isShowSelf, $isShowRelated); return $this->factory->createRelationshipObject($name, $data, $links, $meta, $isShowData, false); }
/** * @inheritdoc */ public function getRelationshipObjectIterator($resource) { foreach ($this->getRelationships($resource) as $name => $desc) { $data = $this->readData($desc); $meta = $this->getValue($desc, self::META, null); $isShowSelf = $this->getValue($desc, self::SHOW_SELF, false) === true; $isShowRelated = $this->getValue($desc, self::SHOW_RELATED, false) === true; $isShowData = $this->getValue($desc, self::SHOW_DATA, true) === true; $links = $this->readLinks($name, $desc, $isShowSelf, $isShowRelated); (yield $this->factory->createRelationshipObject($name, $data, $links, $meta, $isShowData)); } }