1 | <?php |
||
7 | abstract class JsonApiSerializer implements JsonSerializable |
||
8 | { |
||
9 | /** |
||
10 | * The JSON API version being implemented. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | const JSON_API_VERSION = '1.0'; |
||
15 | |||
16 | /** |
||
17 | * Meta information to include. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $meta = []; |
||
22 | |||
23 | /** |
||
24 | * Resource links to include. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $links = []; |
||
29 | |||
30 | /** |
||
31 | * Return primary data for the JSON API document. |
||
32 | * |
||
33 | * @return mixed |
||
34 | */ |
||
35 | abstract protected function getPrimaryData(); |
||
36 | |||
37 | /** |
||
38 | * Add included meta information. |
||
39 | * |
||
40 | * @param string|array $key |
||
41 | * @param string|int|null $value |
||
42 | */ |
||
43 | public function addMeta($key, $value = null) |
||
47 | |||
48 | /** |
||
49 | * Add one or more included links. |
||
50 | * |
||
51 | * @param string|array $key |
||
52 | * @param string|int|null $value |
||
53 | */ |
||
54 | public function addLinks($key, $value = null) |
||
58 | |||
59 | /** |
||
60 | * Serialise JSON API document to an array. |
||
61 | * |
||
62 | * @return array |
||
63 | */ |
||
64 | public function serializeToObject() |
||
74 | |||
75 | /** |
||
76 | * Convert the object into something JSON serializable. |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | public function jsonSerialize() |
||
84 | |||
85 | /** |
||
86 | * Serialise JSON API document to a JSON string. |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | public function serializeToJson() |
||
94 | |||
95 | /** |
||
96 | * Return any secondary included resource data. |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | protected function getIncludedData() |
||
104 | |||
105 | /** |
||
106 | * Return JSON API implementation information. |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | private function getDocumentMeta() |
||
116 | } |
||
117 |