1 | <?php |
||
7 | class ResourceSerializer extends JsonApiSerializer |
||
8 | { |
||
9 | /** |
||
10 | * The model instance to transform. |
||
11 | * |
||
12 | * @var \Illuminate\Database\Eloquent\Model |
||
13 | */ |
||
14 | protected $record; |
||
15 | |||
16 | /** |
||
17 | * The subset of attributes to return on each resource type. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $fields; |
||
22 | |||
23 | /** |
||
24 | * The relationship paths to match for included resources. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $include; |
||
29 | |||
30 | /** |
||
31 | * The named relationships to list against this resource. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $relationships; |
||
36 | |||
37 | /** |
||
38 | * Create a new JSON API resource serializer. |
||
39 | * |
||
40 | * @param \Illuminate\Database\Eloquent\Model $record The model instance to serialise |
||
41 | * @param array|null $fields The subset of fields to return on each resource type |
||
42 | * @param array|null $include The paths of relationships to include |
||
43 | * @param array|null $relationships Additional named relationships to list |
||
44 | */ |
||
45 | 22 | public function __construct($record, array $fields = [], array $include = [], array $relationships = []) |
|
63 | |||
64 | /** |
||
65 | * Limit which relations can be included. |
||
66 | * |
||
67 | * @param array $include |
||
68 | */ |
||
69 | 1 | public function scopeIncludes($include) |
|
73 | |||
74 | /** |
||
75 | * Return a JSON API resource identifier object for the primary record. |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | 22 | public function toResourceIdentifier() |
|
86 | |||
87 | /** |
||
88 | * Return a base JSON API resource object for the primary record containing |
||
89 | * only immediate attributes. |
||
90 | * |
||
91 | * @return array |
||
92 | */ |
||
93 | 18 | public function toBaseResourceObject() |
|
99 | |||
100 | /** |
||
101 | * Return a full JSON API resource object for the primary record. |
||
102 | * |
||
103 | * @return array |
||
104 | */ |
||
105 | 16 | public function toResourceObject() |
|
111 | |||
112 | /** |
||
113 | * Return primary data for the JSON API document. |
||
114 | * |
||
115 | * @return mixed |
||
116 | */ |
||
117 | 6 | protected function getPrimaryData() |
|
121 | |||
122 | /** |
||
123 | * Return any secondary included resource objects. |
||
124 | * |
||
125 | * @throws \Huntie\JsonApi\Exceptions\InvalidRelationPathException |
||
126 | * |
||
127 | * @return \Illuminate\Support\Collection |
||
128 | */ |
||
129 | 12 | public function getIncluded() |
|
166 | |||
167 | /** |
||
168 | * Return the primary resource type name. |
||
169 | */ |
||
170 | 22 | protected function getResourceType(): string |
|
180 | |||
181 | /** |
||
182 | * Return the primary key value for the resource. |
||
183 | * |
||
184 | * @return int|string |
||
185 | */ |
||
186 | 22 | protected function getPrimaryKey() |
|
192 | |||
193 | /** |
||
194 | * Return the attribute subset requested for the primary resource type. |
||
195 | */ |
||
196 | 18 | protected function getRequestedFields(): array |
|
202 | |||
203 | /** |
||
204 | * Return the deepest relationship paths that should be used to resolve |
||
205 | * all included relations. |
||
206 | */ |
||
207 | 12 | protected function getIncludePaths(): array |
|
218 | |||
219 | /** |
||
220 | * Return the attribute object data for the primary record. |
||
221 | */ |
||
222 | 18 | protected function transformRecordAttributes(): array |
|
233 | |||
234 | /** |
||
235 | * Return a collection of JSON API resource identifier objects by each |
||
236 | * relation on the primary record. |
||
237 | * |
||
238 | * @throws \Huntie\JsonApi\Exceptions\InvalidRelationPathException |
||
239 | * |
||
240 | * @return \Illuminate\Support\Collection |
||
241 | */ |
||
242 | protected function transformRecordRelations() |
||
250 | } |
||
251 |
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.