/** * @param string $relationship * @return \WoohooLabs\Yin\JsonApi\Hydrator\Relationship\ToManyRelationship|null */ public function getResourceToManyRelationship($relationship) { $data = $this->getResource(); if (isset($data["relationships"][$relationship]) === false) { return null; } $resourceIdentifiers = []; foreach ($data["relationships"][$relationship] as $item) { $resourceIdentifiers[] = ResourceIdentifier::fromArray($item); } new ToManyRelationship($resourceIdentifiers); }
/** * @param array $relationship * @return \WoohooLabs\Yin\JsonApi\Hydrator\Relationship\ToOneRelationship| * \WoohooLabs\Yin\JsonApi\Hydrator\Relationship\ToManyRelationship|null */ private function createRelationship(array $relationship) { if (isset($relationship["data"]) === false) { return null; } if ($this->isAssociativeArray($relationship["data"]) === true) { $result = new ToOneRelationship(ResourceIdentifier::fromArray($relationship["data"])); } else { $result = new ToManyRelationship(); foreach ($relationship["data"] as $relationship) { $result->addResourceIdentifier(ResourceIdentifier::fromArray($relationship)); } } return $result; }
/** * @param array|null $relationship * @param ExceptionFactoryInterface $exceptionFactory * @return \WoohooLabs\Yin\JsonApi\Hydrator\Relationship\ToOneRelationship| * \WoohooLabs\Yin\JsonApi\Hydrator\Relationship\ToManyRelationship|null */ private function createRelationship($relationship, ExceptionFactoryInterface $exceptionFactory) { if (array_key_exists("data", $relationship) === false) { return null; } //If this is a request to clear the relationship, we create an empty relationship if (is_null($relationship["data"])) { $result = new ToOneRelationship(); } elseif ($this->isAssociativeArray($relationship["data"]) === true) { $result = new ToOneRelationship(ResourceIdentifier::fromArray($relationship["data"], $exceptionFactory)); } else { $result = new ToManyRelationship(); foreach ($relationship["data"] as $relationship) { $result->addResourceIdentifier(ResourceIdentifier::fromArray($relationship, $exceptionFactory)); } } return $result; }