1 | <?php |
||
15 | final class Denormalizer implements DenormalizerInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var DenormalizerObjectMappingRegistryInterface |
||
19 | */ |
||
20 | private $denormalizerObjectMappingRegistry; |
||
21 | |||
22 | /** |
||
23 | * @var LoggerInterface |
||
24 | */ |
||
25 | private $logger; |
||
26 | |||
27 | /** |
||
28 | * @param DenormalizerObjectMappingRegistryInterface $denormalizerObjectMappingRegistry |
||
29 | * @param LoggerInterface|null $logger |
||
30 | */ |
||
31 | 13 | public function __construct( |
|
38 | |||
39 | /** |
||
40 | * @param object|string $object |
||
41 | * @param array $data |
||
42 | * @param DenormalizerContextInterface|null $context |
||
43 | * @param string $path |
||
44 | * |
||
45 | * @return object |
||
46 | * |
||
47 | * @throws DeserializerLogicException |
||
48 | * @throws DeserializerRuntimeException |
||
49 | */ |
||
50 | 13 | public function denormalize($object, array $data, DenormalizerContextInterface $context = null, string $path = '') |
|
99 | |||
100 | /** |
||
101 | * @param string $class |
||
102 | * |
||
103 | * @return DenormalizationObjectMappingInterface |
||
104 | * |
||
105 | * @throws DeserializerLogicException |
||
106 | */ |
||
107 | 13 | private function getObjectMapping(string $class): DenormalizationObjectMappingInterface |
|
117 | |||
118 | /** |
||
119 | * @param DenormalizationObjectMappingInterface $objectMapping |
||
120 | * @param string $path |
||
121 | * @param string|null $type |
||
122 | * |
||
123 | * @return object |
||
124 | */ |
||
125 | 10 | private function createNewObject( |
|
143 | |||
144 | /** |
||
145 | * @param DenormalizerContextInterface $context |
||
146 | * @param DenormalizationFieldMappingInterface $denormalizationFieldMapping |
||
147 | * @param string $path |
||
148 | * @param array $data |
||
149 | * @param object $object |
||
150 | */ |
||
151 | 9 | private function denormalizeField( |
|
152 | DenormalizerContextInterface $context, |
||
153 | DenormalizationFieldMappingInterface $denormalizationFieldMapping, |
||
154 | string $path, |
||
155 | string $name, |
||
156 | array $data, |
||
157 | $object |
||
158 | ) { |
||
159 | 9 | if (!$this->isCompliant($context, $denormalizationFieldMapping, $object)) { |
|
160 | 1 | return; |
|
161 | } |
||
162 | |||
163 | 8 | if (!$this->isWithinGroup($context, $denormalizationFieldMapping)) { |
|
164 | 1 | return; |
|
165 | } |
||
166 | |||
167 | 7 | $subPath = $this->getSubPathByName($path, $name); |
|
168 | |||
169 | 7 | $this->logger->info('deserialize: path {path}', ['path' => $subPath]); |
|
170 | |||
171 | 7 | $fieldDenormalizer = $denormalizationFieldMapping->getFieldDenormalizer(); |
|
172 | 7 | $fieldDenormalizer->denormalizeField($subPath, $object, $data[$name], $context, $this); |
|
173 | 7 | } |
|
174 | |||
175 | /** |
||
176 | * @param string $path |
||
177 | * @param array $names |
||
178 | */ |
||
179 | 1 | private function handleNotAllowedAdditionalFields(string $path, array $names) |
|
189 | |||
190 | /** |
||
191 | * @param DenormalizerContextInterface $context |
||
192 | * @param DenormalizationFieldMappingInterface $mapping |
||
193 | * @param object $object |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | 9 | private function isCompliant( |
|
198 | DenormalizerContextInterface $context, |
||
199 | DenormalizationFieldMappingInterface $mapping, |
||
200 | $object |
||
201 | ): bool { |
||
202 | 9 | if (!is_callable([$mapping, 'getPolicy'])) { |
|
203 | 7 | return true; |
|
204 | } |
||
205 | |||
206 | 2 | return $mapping->getPolicy()->isCompliant($context, $object); |
|
207 | } |
||
208 | |||
209 | /** |
||
210 | * @param DenormalizerContextInterface $context |
||
211 | * @param DenormalizationFieldMappingInterface $fieldMapping |
||
212 | * |
||
213 | * @return bool |
||
214 | */ |
||
215 | 8 | private function isWithinGroup( |
|
231 | |||
232 | /** |
||
233 | * @param string $path |
||
234 | * @param string $name |
||
235 | * |
||
236 | * @return string |
||
237 | */ |
||
238 | 8 | private function getSubPathByName(string $path, string $name): string |
|
242 | |||
243 | /** |
||
244 | * @param string $path |
||
245 | * @param array $names |
||
246 | * |
||
247 | * @return array |
||
248 | */ |
||
249 | 1 | private function getSubPathsByNames(string $path, array $names): array |
|
258 | |||
259 | /** |
||
260 | * @param DenormalizerContextInterface $context |
||
261 | * @param DenormalizationObjectMappingInterface $objectMapping |
||
262 | * @param object $object |
||
263 | * @param array $missingFields |
||
264 | * @param string $path |
||
265 | * @param string|null $type |
||
266 | */ |
||
267 | 2 | private function resetMissingFields( |
|
288 | } |
||
289 |
This method has been deprecated.