1 | <?php |
||
21 | class HashHandler |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * @var RequestStack |
||
26 | */ |
||
27 | private $requestStack; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $seenCounter = []; |
||
33 | |||
34 | /** |
||
35 | * @var null|object |
||
36 | */ |
||
37 | private $currentRequestContent = null; |
||
38 | |||
39 | /** |
||
40 | * HashHandler constructor. |
||
41 | * |
||
42 | * @param RequestStack $requestStack request stack |
||
43 | */ |
||
44 | 4 | public function __construct(RequestStack $requestStack) |
|
48 | |||
49 | /** |
||
50 | * Serialize Hash object |
||
51 | * |
||
52 | * @param JsonSerializationVisitor $visitor Visitor |
||
53 | * @param Hash $data Data |
||
54 | * @param array $type Type |
||
55 | * @param Context $context Context |
||
56 | * @return Hash |
||
57 | */ |
||
58 | 2 | public function serializeHashToJson( |
|
66 | |||
67 | /** |
||
68 | * Deserialize Hash object |
||
69 | * |
||
70 | * @param JsonDeserializationVisitor $visitor Visitor |
||
71 | * @param array $data Data |
||
72 | * @param array $type Type |
||
73 | * @param Context $context Context |
||
74 | * @return Hash |
||
75 | */ |
||
76 | 2 | public function deserializeHashFromJson( |
|
108 | |||
109 | /** |
||
110 | * returns the json_decoded content of the current request. if there is no request, it |
||
111 | * will return null |
||
112 | * |
||
113 | * @return mixed|null|object the json_decoded request content |
||
114 | */ |
||
115 | 2 | private function getCurrentRequestContent() |
|
123 | |||
124 | /** |
||
125 | * this checks for a special case which this new approach is really flawed. if this |
||
126 | * handler is used to deserialize an array, we are not aware of the current index in the iteration. |
||
127 | * so we record for what we have been called how many times ($this->seenCounter) and |
||
128 | * if this function here returns true, we only return the index specified by the seencounter. |
||
129 | * |
||
130 | * we assume that we are in this special case when the userData (the one parsed from the request) |
||
131 | * has sequential keys *and* they are different from the keys that the serializer data gives us. |
||
132 | * |
||
133 | * @param array $userArr data from users request |
||
134 | * @param array $serializerArr data from the serializer |
||
135 | * |
||
136 | * @return bool true if yes, false otherwise |
||
137 | */ |
||
138 | private function isSequentialArrayCase($userArr, $serializerArr) |
||
146 | |||
147 | /** |
||
148 | * convenience function for the location counting for the "sequential array case" as described above. |
||
149 | * |
||
150 | * @param array $location the current path from the serializer |
||
151 | * |
||
152 | * @return int the counter |
||
153 | */ |
||
154 | private function getLocationCounter($location) |
||
164 | } |
||
165 |