WoohooLabs\Yin\JsonApi\Schema\ResourceIdentifier::fromArray PHP Method

fromArray() public static method

public static fromArray ( array $array, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory )
$array array
$exceptionFactory WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface
    public static function fromArray(array $array, ExceptionFactoryInterface $exceptionFactory)
    {
        if (isset($array["type"]) === false) {
            throw $exceptionFactory->createResourceIdentifierTypeMissing($array);
        }
        if (isset($array["id"]) === false) {
            throw $exceptionFactory->createResourceIdentifierIdMissing($array);
        }
        $resourceIdentifier = new self();
        $resourceIdentifier->setType($array["type"]);
        $resourceIdentifier->setId($array["id"]);
        if (isset($array["meta"]) === true) {
            $resourceIdentifier->setMeta($array["meta"]);
        }
        return $resourceIdentifier;
    }

Usage Example

示例#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);
 }
All Usage Examples Of WoohooLabs\Yin\JsonApi\Schema\ResourceIdentifier::fromArray