1 | <?php |
||
7 | abstract class JsonApiSerializer implements JsonSerializable |
||
8 | { |
||
9 | /** |
||
10 | * Meta information to include. |
||
11 | * |
||
12 | * @var \Illuminate\Support\Collection |
||
13 | */ |
||
14 | protected $meta; |
||
15 | |||
16 | /** |
||
17 | * Resource links to include. |
||
18 | * |
||
19 | * @var \Illuminate\Support\Collection |
||
20 | */ |
||
21 | protected $links; |
||
22 | |||
23 | /** |
||
24 | * Create a new JSON API document serializer. |
||
25 | */ |
||
26 | public function __construct() |
||
31 | |||
32 | /** |
||
33 | * Return primary data for the JSON API document. |
||
34 | * |
||
35 | * @return mixed |
||
36 | */ |
||
37 | abstract protected function getPrimaryData(); |
||
38 | |||
39 | /** |
||
40 | * Add included meta information. |
||
41 | * |
||
42 | * @param string|array $key |
||
43 | * @param string|int|null $value |
||
44 | */ |
||
45 | public function addMeta($key, $value = null) |
||
49 | |||
50 | /** |
||
51 | * Add one or more included links. |
||
52 | * |
||
53 | * @param string|array $key |
||
54 | * @param string|int|null $value |
||
55 | */ |
||
56 | public function addLinks($key, $value = null) |
||
60 | |||
61 | /** |
||
62 | * Serialise JSON API document to an array. |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | public function serializeToObject() |
||
75 | |||
76 | /** |
||
77 | * Convert the object into something JSON serializable. |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | public function jsonSerialize() |
||
85 | |||
86 | /** |
||
87 | * Serialise JSON API document to a JSON string. |
||
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | public function serializeToJson() |
||
95 | |||
96 | /** |
||
97 | * Return any secondary included resource data. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | protected function getIncludedData() |
||
105 | } |
||
106 |