1 | <?php |
||
8 | class ObjectNormalizer |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | private $classAnnotation; |
||
14 | |||
15 | /** |
||
16 | * Maps objects to their corresponding index. Used to deconstruct cyclic references when normalizing. |
||
17 | * |
||
18 | * @var \SplObjectStorage |
||
19 | */ |
||
20 | private $objectToIndex; |
||
21 | |||
22 | /** |
||
23 | * Maps indexes to their corresponding object. Used to reconstruct cyclic references when de-normalizing. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | private $indexToObject = []; |
||
28 | |||
29 | /** |
||
30 | * @var integer |
||
31 | */ |
||
32 | private $objectIndex = 0; |
||
33 | |||
34 | |||
35 | /** |
||
36 | * @param string $classAnnotation |
||
37 | */ |
||
38 | 21 | public function __construct($classAnnotation = '@type') |
|
43 | |||
44 | /** |
||
45 | * @param object $object |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | 11 | public function normalize($object) |
|
58 | |||
59 | /** |
||
60 | * @param array $data |
||
61 | * |
||
62 | * @return object |
||
63 | */ |
||
64 | 10 | public function denormalize(array $data) |
|
69 | |||
70 | 19 | private function reset() |
|
76 | |||
77 | /** |
||
78 | * Extract the data from an object |
||
79 | * |
||
80 | * @param object $object |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | 10 | private function normalizeObject($object) |
|
96 | |||
97 | /** |
||
98 | * Parse the data to be json encoded |
||
99 | * |
||
100 | * @param mixed $value |
||
101 | * |
||
102 | * @return mixed |
||
103 | * @throws JsonSerializerException |
||
104 | */ |
||
105 | 8 | private function normalizeValue($value) |
|
125 | |||
126 | /** |
||
127 | * Returns an array containing the object's properties to values |
||
128 | * |
||
129 | * @param object $object |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | 10 | private function extractObjectProperties($object) |
|
163 | |||
164 | /** |
||
165 | * Parse the json decode to convert to objects again |
||
166 | * |
||
167 | * @param mixed $data |
||
168 | * |
||
169 | * @return mixed |
||
170 | */ |
||
171 | 10 | private function denormalizeData($data) |
|
183 | |||
184 | /** |
||
185 | * Convert the serialized array into an object |
||
186 | * |
||
187 | * @param array $data |
||
188 | * |
||
189 | * @return object |
||
190 | * @throws JsonSerializerException |
||
191 | */ |
||
192 | 10 | private function denormalizeObject(array $data) |
|
231 | |||
232 | /** |
||
233 | * @param string $className |
||
234 | * @param array $attributes |
||
235 | * |
||
236 | * @return \DateTime |
||
237 | */ |
||
238 | 1 | private function denormalizeDateTime($className, array $attributes) |
|
248 | } |
||
249 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.