1 | <?php |
||
8 | class JsonApiSerializer |
||
9 | { |
||
10 | /** |
||
11 | * The model instance to transform. |
||
12 | * |
||
13 | * @var \Illuminate\Database\Eloquent\Model |
||
14 | */ |
||
15 | protected $record; |
||
16 | |||
17 | /** |
||
18 | * The relationships to return. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $relationships; |
||
23 | |||
24 | /** |
||
25 | * The subset of record attributes to return. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $fields; |
||
30 | |||
31 | /** |
||
32 | * The relationships to load and include. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $include; |
||
37 | |||
38 | /** |
||
39 | * Meta information to include. |
||
40 | * |
||
41 | * @var \Illuminate\Support\Collection |
||
42 | */ |
||
43 | protected $meta; |
||
44 | |||
45 | /** |
||
46 | * Resource links to include. |
||
47 | * |
||
48 | * @var \Illuminate\Support\Collection |
||
49 | */ |
||
50 | protected $links; |
||
51 | |||
52 | /** |
||
53 | * Create a new JSON API resource serializer. |
||
54 | * |
||
55 | * @param Model $record The model instance to serialise |
||
56 | * @param array|null $fields Subset of fields to return |
||
57 | * @param array|null $include Relations to include |
||
58 | */ |
||
59 | public function __construct($record, array $fields = [], array $include = []) |
||
68 | |||
69 | /** |
||
70 | * Limit which relations can be included. |
||
71 | * |
||
72 | * @param array $include |
||
73 | */ |
||
74 | public function scopeIncludes($include) |
||
78 | |||
79 | /** |
||
80 | * Add meta information to the returned object. |
||
81 | * |
||
82 | * @param string|array $key |
||
83 | * @param string|int|null $value |
||
84 | */ |
||
85 | public function addMeta($key, $value = null) |
||
89 | |||
90 | /** |
||
91 | * Add one or more links to the returned object. |
||
92 | * |
||
93 | * @param string|array $key |
||
94 | * @param string|int|null $value |
||
95 | */ |
||
96 | public function addLinks($key, $value = null) |
||
100 | |||
101 | /** |
||
102 | * Return a JSON API resource identifier object for the primary record. |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | public function toResourceIdentifier() |
||
113 | |||
114 | /** |
||
115 | * Return a JSON API resource object for the primary record. |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | public function toResourceObject() |
||
128 | |||
129 | /** |
||
130 | * Serialise complete JSON API document to an array. |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | public function serialiseToObject() |
||
143 | |||
144 | /** |
||
145 | * Serialise complete JSON API document to a JSON string. |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | public function serializeToJson() |
||
153 | |||
154 | /** |
||
155 | * Return the primary record type name. |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | protected function getRecordType() |
||
163 | |||
164 | /** |
||
165 | * Return the attribute object data for the primary record. |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | protected function transformRecordAttributes() |
||
180 | |||
181 | /** |
||
182 | * Return a collection of JSON API resource identifier objects by each |
||
183 | * relation on the primary record. |
||
184 | * |
||
185 | * @return array |
||
186 | */ |
||
187 | protected function transformRecordRelations() |
||
208 | |||
209 | /** |
||
210 | * Return a collection of JSON API resource objects for each included |
||
211 | * relationship. |
||
212 | * |
||
213 | * @return array |
||
214 | */ |
||
215 | protected function transformIncludedRelations() |
||
227 | } |
||
228 |