/** * @param string $name * @return ContainerInterface */ public function getSchemas($name = null) { $name = $name ?: static::DEFAULTS; if (static::DEFAULTS !== $name && !$this->namespaced) { throw new \RuntimeException(sprintf('Schemas configuration is not namespaced, so cannot get "%s".', $name)); } $defaults = $this->get(static::DEFAULTS); $schemas = static::DEFAULTS === $name ? $defaults : array_merge($defaults, $this->get($name)); return $this->factory->createContainer($schemas); }
/** * @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 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 string $relationshipName * @param array $description * @param bool $isShowSelf * @param bool $isShowRelated * * @return array <string,LinkInterface> */ protected function readLinks($relationshipName, array $description, $isShowSelf, $isShowRelated) { $links = $this->getValue($description, self::LINKS, []); if ($isShowSelf === true && isset($links[LinkInterface::SELF]) === false) { $links[LinkInterface::SELF] = $this->factory->createLink('relationships/' . $relationshipName); } if ($isShowRelated === true && isset($links[LinkInterface::RELATED]) === false) { $links[LinkInterface::RELATED] = $this->factory->createLink($relationshipName); } return $links; }