Author: Toby Zerner (toby.zerner@gmail.com)
コード例 #1
0
ファイル: Resource.php プロジェクト: tobscure/json-api
 /**
  * Get an array of built relationships.
  *
  * @return \Tobscure\JsonApi\Relationship[]
  */
 protected function buildRelationships()
 {
     if (isset($this->relationships)) {
         return $this->relationships;
     }
     $paths = Util::parseRelationshipPaths($this->includes);
     $relationships = [];
     foreach ($paths as $name => $nested) {
         $relationship = $this->serializer->getRelationship($this->data, $name);
         if ($relationship) {
             $relationshipData = $relationship->getData();
             if ($relationshipData instanceof ElementInterface) {
                 $relationshipData->with($nested)->fields($this->fields);
             }
             $relationships[$name] = $relationship;
         }
     }
     return $this->relationships = $relationships;
 }
コード例 #2
0
 /**
  * Serialize the data as appropriate.
  *
  * @param SerializerInterface $serializer
  * @param array $data
  * @return \Tobscure\JsonApi\Elements\Collection
  */
 protected function serialize(SerializerInterface $serializer, $data)
 {
     return $serializer->collection($data);
 }
コード例 #3
0
 /**
  * Serialize the data as appropriate.
  *
  * @param \Tobscure\JsonApi\SerializerInterface $serializer
  * @param array $data
  * @return \Tobscure\JsonApi\Elements\Resource
  */
 protected function serialize(SerializerInterface $serializer, $data)
 {
     return $serializer->resource($data);
 }