fromArray() public static method

public static fromArray ( array $array, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory )
$array array
$exceptionFactory WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface
Beispiel #1
0
 /**
  * @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);
 }
Beispiel #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;
 }
Beispiel #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;
 }