상속: use trait MetaTrait
예제 #1
0
파일: Request.php 프로젝트: cwdt/yin
 /**
  * @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);
 }
예제 #2
0
 /**
  * @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;
 }
예제 #3
0
 /**
  * @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;
 }