11<?php
2- /**
3- * This file is part of JSON:API implementation for PHP.
2+ declare (strict_types=1 );
3+
4+ /*
5+ * This file is part of JSON:API implementation for PHP.
46 *
5- * (c) Alexey Karapetov <karapetov@gmail.com>
7+ * (c) Alexey Karapetov <karapetov@gmail.com>
68 *
7- * For the full copyright and license information, please view the LICENSE
8- * file that was distributed with this source code.
9+ * For the full copyright and license information, please view the LICENSE
10+ * file that was distributed with this source code.
911 */
1012
11- declare (strict_types=1 );
12-
1313namespace JsonApiPhp \JsonApi \Document ;
1414
15- use JsonApiPhp \JsonApi \Document \Resource \IdentifiableResource ;
16- use JsonApiPhp \JsonApi \HasLinksAndMeta ;
15+ use JsonApiPhp \JsonApi \Document \Resource \ResourceInterface ;
16+ use JsonApiPhp \JsonApi \Document \ Resource \ ResourceObject ;
1717
1818final class Document implements \JsonSerializable
1919{
2020 const MEDIA_TYPE = 'application/vnd.api+json ' ;
2121 const DEFAULT_API_VERSION = '1.0 ' ;
2222
23- use HasLinksAndMeta;
23+ use LinksTrait;
24+ use MetaTrait;
2425
2526 private $ data ;
2627 private $ errors ;
27- private $ meta ;
28- private $ json_api ;
29- private $ links ;
28+ private $ api ;
3029 private $ included ;
3130 private $ is_sparse = false ;
3231
@@ -48,14 +47,14 @@ public static function fromErrors(Error ...$errors): self
4847 return $ doc ;
4948 }
5049
51- public static function fromResource (IdentifiableResource $ data ): self
50+ public static function fromResource (ResourceInterface $ data ): self
5251 {
5352 $ doc = new self ;
5453 $ doc ->data = $ data ;
5554 return $ doc ;
5655 }
5756
58- public static function fromResources (IdentifiableResource ...$ data ): self
57+ public static function fromResources (ResourceInterface ...$ data ): self
5958 {
6059 $ doc = new self ;
6160 $ doc ->data = $ data ;
@@ -64,15 +63,15 @@ public static function fromResources(IdentifiableResource ...$data): self
6463
6564 public function setApiVersion (string $ version = self ::DEFAULT_API_VERSION )
6665 {
67- $ this ->json_api ['version ' ] = $ version ;
66+ $ this ->api ['version ' ] = $ version ;
6867 }
6968
7069 public function setApiMeta (array $ meta )
7170 {
72- $ this ->json_api ['meta ' ] = $ meta ;
71+ $ this ->api ['meta ' ] = $ meta ;
7372 }
7473
75- public function setIncluded (IdentifiableResource ...$ included )
74+ public function setIncluded (ResourceObject ...$ included )
7675 {
7776 $ this ->included = $ included ;
7877 }
@@ -90,7 +89,7 @@ public function jsonSerialize()
9089 'data ' => $ this ->data ,
9190 'errors ' => $ this ->errors ,
9291 'meta ' => $ this ->meta ,
93- 'jsonapi ' => $ this ->json_api ,
92+ 'jsonapi ' => $ this ->api ,
9493 'links ' => $ this ->links ,
9594 'included ' => $ this ->included ,
9695 ],
@@ -113,9 +112,9 @@ private function enforceFullLinkage()
113112 }
114113 }
115114
116- private function anotherIncludedResourceIdentifies (IdentifiableResource $ resource ): bool
115+ private function anotherIncludedResourceIdentifies (ResourceObject $ resource ): bool
117116 {
118- /** @var IdentifiableResource $included_resource */
117+ /** @var ResourceObject $included_resource */
119118 foreach ($ this ->included as $ included_resource ) {
120119 if ($ included_resource !== $ resource && $ included_resource ->identifies ($ resource )) {
121120 return true ;
@@ -124,9 +123,9 @@ private function anotherIncludedResourceIdentifies(IdentifiableResource $resourc
124123 return false ;
125124 }
126125
127- private function hasLinkTo (IdentifiableResource $ resource ): bool
126+ private function hasLinkTo (ResourceObject $ resource ): bool
128127 {
129- /** @var IdentifiableResource $my_resource */
128+ /** @var ResourceInterface $my_resource */
130129 foreach ($ this ->toResources () as $ my_resource ) {
131130 if ($ my_resource ->identifies ($ resource )) {
132131 return true ;
@@ -135,9 +134,9 @@ private function hasLinkTo(IdentifiableResource $resource): bool
135134 return false ;
136135 }
137136
138- private function toResources (): \Generator
137+ private function toResources (): \Iterator
139138 {
140- if ($ this ->data instanceof IdentifiableResource ) {
139+ if ($ this ->data instanceof ResourceInterface ) {
141140 yield $ this ->data ;
142141 } elseif (is_array ($ this ->data )) {
143142 foreach ($ this ->data as $ datum ) {
0 commit comments