/** * Set path to current frame. */ private function setCurrentPath() { if ($this->previous === null || $this->previous->getPath() === null) { $this->path = $this->relationship->getName(); } else { $this->path = $this->previous->getPath() . '.' . $this->relationship->getName(); } }
/** * Set path to current frame. */ private function setCurrentPath() { if ($this->previous === null || $this->previous->getPath() === null) { $this->path = $this->relationship->getName(); } else { $this->path = $this->previous->getPath() . DocumentInterface::PATH_SEPARATOR . $this->relationship->getName(); } }
/** * @param ResourceObjectInterface $parent * @param RelationshipObjectInterface $relation * @param ResourceObjectInterface $resource * * @return array */ private function getRelationRepresentation(ResourceObjectInterface $parent, RelationshipObjectInterface $relation, ResourceObjectInterface $resource) { assert('$relation->getName() !== \'' . Document::KEYWORD_SELF . '\'', '"self" is a reserved keyword and cannot be used as a related resource link name'); $representation = []; if ($relation->isShowData() === true) { $representation[Document::KEYWORD_LINKAGE_DATA][] = $this->getLinkageRepresentation($resource); } if (($meta = $relation->getMeta()) !== null) { $representation[Document::KEYWORD_META] = $meta; } $baseUrl = null; if (($selfSubLink = $parent->getSelfSubLink()) !== null) { $baseUrl = $selfSubLink->isTreatAsHref() === true ? $selfSubLink->getSubHref() . '/' : $this->document->getUrlPrefix() . $selfSubLink->getSubHref() . '/'; } foreach ($relation->getLinks() as $name => $link) { $representation[Document::KEYWORD_LINKS][$name] = $this->getLinkRepresentation($baseUrl, $link); } return $representation; }
/** * @param ResourceObjectInterface $parent * @param RelationshipObjectInterface $relation * * @return array */ private function getRelationRepresentation(ResourceObjectInterface $parent, RelationshipObjectInterface $relation) { // "self" is a reserved keyword and cannot be used as a related resource link name $isOk = $relation->getName() !== Document::KEYWORD_SELF; $isOk ?: Exceptions::throwInvalidArgument('relation.name', $relation->getName()); $representation = []; if (($meta = $relation->getMeta()) !== null) { $representation[Document::KEYWORD_META] = $meta; } $baseUrl = null; if (($selfSubLink = $parent->getSelfSubLink()) !== null) { $baseUrl = $selfSubLink->isTreatAsHref() === true ? $selfSubLink->getSubHref() . '/' : $this->document->getUrlPrefix() . $selfSubLink->getSubHref() . '/'; } foreach ($relation->getLinks() as $name => $link) { $representation[Document::KEYWORD_LINKS][$name] = $this->getLinkRepresentation($baseUrl, $link); } return $representation; }
/** * @param ResourceObjectInterface $parent * @param RelationshipObjectInterface $relation * * @return array */ private function getRelationRepresentation(ResourceObjectInterface $parent, RelationshipObjectInterface $relation) { $isOk = $relation->getName() !== Document::KEYWORD_SELF; if ($isOk === false) { throw new InvalidArgumentException(T::t('\'%s\' is a reserved keyword and cannot be used as a relationship name in type \'%s\'', [Document::KEYWORD_SELF, $parent->getType()])); } $representation = []; if (($meta = $relation->getMeta()) !== null) { $representation[Document::KEYWORD_META] = $meta; } $baseUrl = $this->document->getUrlPrefix(); foreach ($relation->getLinks() as $name => $link) { $representation[Document::KEYWORD_LINKS][$name] = $this->getLinkRepresentation($baseUrl, $link); } return $representation; }
/** * @inheritdoc */ public function isShouldRelationshipBeInOutput(ResourceObjectInterface $resource, RelationshipObjectInterface $relationship) { $resourceType = $resource->getType(); $resourceFieldSet = $this->getFieldSet($resourceType); return $resourceFieldSet === null ? true : array_key_exists($relationship->getName(), $resourceFieldSet); }