Tobscure\JsonApi\Resource::toArray PHP Метод

toArray() публичный Метод

public toArray ( )
    public function toArray()
    {
        $array = $this->toIdentifier();
        if (!$this->isIdentifier()) {
            $array['attributes'] = $this->getAttributes();
        }
        $relationships = $this->getRelationshipsAsArray();
        if (count($relationships)) {
            $array['relationships'] = $relationships;
        }
        $links = [];
        if (!empty($this->links)) {
            $links = $this->links;
        }
        $serializerLinks = $this->serializer->getLinks($this->data);
        if (!empty($serializerLinks)) {
            $links = array_merge($serializerLinks, $links);
        }
        if (!empty($links)) {
            $array['links'] = $links;
        }
        $meta = [];
        if (!empty($this->meta)) {
            $meta = $this->meta;
        }
        $serializerMeta = $this->serializer->getMeta($this->data);
        if (!empty($serializerMeta)) {
            $meta = array_merge($serializerMeta, $meta);
        }
        if (!empty($meta)) {
            $array['meta'] = $meta;
        }
        return $array;
    }

Usage Example

Пример #1
0
 public function testToArrayIncludesTheResourcesRepresentation()
 {
     $post = (object) ['id' => 1, 'foo' => 'bar'];
     $resource = new Resource($post, new PostSerializer2());
     $document = new Document($resource);
     $this->assertEquals(['data' => $resource->toArray()], $document->toArray());
 }
All Usage Examples Of Tobscure\JsonApi\Resource::toArray