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 record type. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $fields; |
||
23 | |||
24 | /** |
||
25 | * The relationships to load and include. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $include; |
||
30 | |||
31 | /** |
||
32 | * Create a new JSON API collection serializer. |
||
33 | * |
||
34 | * @param \Illuminate\Support\Collection|LengthAwarePaginator $records The collection of records to serialize |
||
35 | * @param array|null $fields Subset of fields to return by record type |
||
36 | * @param array|null $include Relations to include |
||
37 | */ |
||
38 | public function __construct($records, array $fields = [], array $include = []) |
||
53 | |||
54 | /** |
||
55 | * Return a collection of JSON API resource objects for the record set. |
||
56 | * |
||
57 | * @return \Illuminate\Support\Collection |
||
58 | */ |
||
59 | public function toResourceCollection() |
||
65 | |||
66 | /** |
||
67 | * Return primary data for the JSON API document. |
||
68 | * |
||
69 | * @return mixed |
||
70 | */ |
||
71 | protected function getPrimaryData() |
||
75 | |||
76 | /** |
||
77 | * Return any secondary included resource objects. |
||
78 | * |
||
79 | * @throws \Huntie\JsonApi\Exceptions\InvalidRelationPathException |
||
80 | * |
||
81 | * @return \Illuminate\Support\Collection |
||
82 | */ |
||
83 | public function getIncluded() |
||
96 | |||
97 | /** |
||
98 | * Add pagination links and meta information to the main document. |
||
99 | * |
||
100 | * @param LengthAwarePaginator $paginator |
||
101 | */ |
||
102 | protected function addPaginationLinks($paginator) |
||
113 | |||
114 | /** |
||
115 | * Add JSON API pagination parameters to request query set based on |
||
116 | * selected pagination strategy, and return the built URL query string. |
||
117 | * |
||
118 | * @param array $query |
||
119 | * @param int $number |
||
120 | * @param int $size |
||
121 | */ |
||
122 | protected function formatPaginationQueryString(array $query = [], int $number, int $size): string |
||
135 | } |
||
136 |