1 | <?php |
||
19 | class CollectionDocument extends DataDocument implements PaginableInterface, ResourceContainerInterface { |
||
20 | /** @var ResourceInterface[] */ |
||
21 | protected $resources = []; |
||
22 | /** @var array */ |
||
23 | protected static $defaults = [ |
||
24 | /** |
||
25 | * add resources inside relationships to /included when adding resources to the collection |
||
26 | */ |
||
27 | 'includeContainedResources' => true, |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * human api |
||
32 | */ |
||
33 | |||
34 | /** |
||
35 | * generate a CollectionDocument from one or multiple resources |
||
36 | * |
||
37 | * adds included resources if found inside the resource's relationships, use {@see ->addResource()} to change that behavior |
||
38 | * |
||
39 | * @param ResourceInterface ...$resources |
||
40 | * @return CollectionDocument |
||
41 | */ |
||
42 | public static function fromResources(ResourceInterface ...$resources) { |
||
51 | |||
52 | /** |
||
53 | * @param string $type |
||
54 | * @param string|int $id |
||
55 | * @param array $attributes optional, if given a ResourceObject is added, otherwise a ResourceIdentifierObject is added |
||
56 | */ |
||
57 | public function add($type, $id, array $attributes=[]) { |
||
65 | |||
66 | /** |
||
67 | * @inheritDoc |
||
68 | */ |
||
69 | public function setPaginationLinks($previousHref=null, $nextHref=null, $firstHref=null, $lastHref=null) { |
||
83 | |||
84 | /** |
||
85 | * spec api |
||
86 | */ |
||
87 | |||
88 | /** |
||
89 | * add a resource to the collection |
||
90 | * |
||
91 | * adds included resources if found inside the resource's relationships, unless $options['includeContainedResources'] is set to false |
||
92 | * |
||
93 | * @param ResourceInterface $resource |
||
94 | * @param array $options optional {@see CollectionDocument::$defaults} |
||
95 | * |
||
96 | * @throws InputException if the resource is empty |
||
97 | */ |
||
98 | public function addResource(ResourceInterface $resource, array $options=[]) { |
||
113 | |||
114 | /** |
||
115 | * DocumentInterface |
||
116 | */ |
||
117 | |||
118 | /** |
||
119 | * @inheritDoc |
||
120 | */ |
||
121 | public function toArray() { |
||
131 | |||
132 | /** |
||
133 | * ResourceContainerInterface |
||
134 | */ |
||
135 | |||
136 | /** |
||
137 | * @inheritDoc |
||
138 | */ |
||
139 | public function getContainedResources() { |
||
142 | } |
||
143 |