1 | <?php |
||
8 | class CollectionSerializer extends JsonApiSerializer |
||
9 | { |
||
10 | /** |
||
11 | * The collection of records to transform. |
||
12 | * |
||
13 | * @var \Illuminate\Support\Collection |
||
14 | */ |
||
15 | protected $records; |
||
16 | |||
17 | /** |
||
18 | * The subset of attributes to return on each resource type. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $fields; |
||
23 | |||
24 | /** |
||
25 | * The relationship paths to match for included resources. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $include; |
||
30 | |||
31 | /** |
||
32 | * The additional named relationships to list against each resource. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $relationships; |
||
37 | |||
38 | /** |
||
39 | * Create a new JSON API collection serializer. |
||
40 | * |
||
41 | * @param \Illuminate\Support\Collection|LengthAwarePaginator $records The collection of records to serialise |
||
42 | * @param array|null $fields The subset of fields to return on each resource type |
||
|
|||
43 | * @param array|null $include The paths of relationships to include |
||
44 | * @param array|null $relationships Additional named relationships to list |
||
45 | */ |
||
46 | public function __construct($records, array $fields = [], array $include = [], array $relationships = []) |
||
62 | |||
63 | /** |
||
64 | * Return a collection of JSON API resource objects for the record set. |
||
65 | * |
||
66 | * @return \Illuminate\Support\Collection |
||
67 | */ |
||
68 | public function toResourceCollection() |
||
75 | |||
76 | /** |
||
77 | * Return primary data for the JSON API document. |
||
78 | * |
||
79 | * @return mixed |
||
80 | */ |
||
81 | protected function getPrimaryData() |
||
85 | |||
86 | /** |
||
87 | * Return any secondary included resource objects. |
||
88 | * |
||
89 | * @throws \Huntie\JsonApi\Exceptions\InvalidRelationPathException |
||
90 | * |
||
91 | * @return \Illuminate\Support\Collection |
||
92 | */ |
||
93 | public function getIncluded() |
||
106 | |||
107 | /** |
||
108 | * Add pagination links and meta information to the main document. |
||
109 | * |
||
110 | * @param LengthAwarePaginator $paginator |
||
111 | */ |
||
112 | protected function addPaginationLinks($paginator) |
||
127 | |||
128 | /** |
||
129 | * Add JSON API pagination parameters to request query set based on |
||
130 | * selected pagination strategy, and return the built URL query string. |
||
131 | * |
||
132 | * @param array $query |
||
133 | * @param int $number |
||
134 | * @param int $size |
||
135 | */ |
||
136 | protected function formatPaginationQueryString(array $query = [], int $number, int $size): string |
||
149 | } |
||
150 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.