1 | <?php |
||
18 | abstract class SerializerAbstract |
||
19 | { |
||
20 | /** |
||
21 | * Serialize a collection. |
||
22 | * |
||
23 | * @param string $resourceKey |
||
24 | * @param array $data |
||
25 | * |
||
26 | * @return array |
||
27 | */ |
||
28 | abstract public function collection($resourceKey, array $data); |
||
29 | |||
30 | /** |
||
31 | * Serialize an item. |
||
32 | * |
||
33 | * @param string $resourceKey |
||
34 | * @param array $data |
||
35 | * |
||
36 | * @return array |
||
37 | */ |
||
38 | abstract public function item($resourceKey, array $data); |
||
39 | |||
40 | /** |
||
41 | * Serialize the included data. |
||
42 | * |
||
43 | * @param ResourceInterface $resource |
||
44 | * @param array $data |
||
45 | * |
||
46 | * @return array |
||
47 | */ |
||
48 | abstract public function includedData(ResourceInterface $resource, array $data); |
||
49 | |||
50 | /** |
||
51 | * Serialize the meta. |
||
52 | * |
||
53 | * @param array $meta |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | abstract public function meta(array $meta); |
||
58 | |||
59 | /** |
||
60 | * Serialize the paginator. |
||
61 | * |
||
62 | * @param PaginatorInterface $paginator |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | abstract public function paginator(PaginatorInterface $paginator); |
||
67 | |||
68 | /** |
||
69 | * Serialize the cursor. |
||
70 | * |
||
71 | * @param CursorInterface $cursor |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | abstract public function cursor(CursorInterface $cursor); |
||
76 | |||
77 | 33 | public function mergeIncludes($transformedData, $includedData) |
|
78 | { |
||
79 | // If the serializer does not want the includes to be side-loaded then |
||
80 | // the included data must be merged with the transformed data. |
||
81 | 33 | if (! $this->sideloadIncludes()) { |
|
82 | 7 | return array_merge($transformedData, $includedData); |
|
83 | } |
||
84 | |||
85 | 26 | return $transformedData; |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Indicates if includes should be side-loaded. |
||
90 | * |
||
91 | * @return bool |
||
92 | */ |
||
93 | 13 | public function sideloadIncludes() |
|
97 | |||
98 | /** |
||
99 | * Hook for the serializer to inject custom data based on the relationships of the resource. |
||
100 | * |
||
101 | * @param array $data |
||
102 | * @param array $rawIncludedData |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | 1 | public function injectData($data, $rawIncludedData) |
|
110 | |||
111 | /** |
||
112 | * Hook for the serializer to modify the final list of includes. |
||
113 | * |
||
114 | * @param array $includedData |
||
115 | * @param array $data |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | 1 | public function filterIncludes($includedData, $data) |
|
123 | |||
124 | /** |
||
125 | * Get the mandatory fields for the serializer |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | public function getMandatoryFields() |
||
133 | } |
||
134 |