| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Chubbyphp\Deserialization; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Chubbyphp\Deserialization\Decoder\DecoderInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Chubbyphp\Deserialization\Denormalizer\DenormalizerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | final class Deserializer implements DeserializerInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * @var DecoderInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private $decoder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @var DenormalizerInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     private $denormalizer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function __construct(DecoderInterface $decoder, DenormalizerInterface $denormalizer) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->decoder = $decoder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->denormalizer = $denormalizer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 4 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 4 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 4 |  |      * @param object|string $object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 4 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @return object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function deserialize( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $object, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         string $data, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         string $contentType, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         DenormalizerContextInterface $context = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         string $path = '' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return $this->denormalizer->denormalize($object, $this->decoder->decode($data, $contentType), $context, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @return string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     public function getContentTypes(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  |         return $this->decoder->getContentTypes(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @throws DeserializerLogicException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @throws DeserializerRuntimeException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 55 | 1 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |     public function decode(string $data, string $contentType): array | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 1 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         return $this->decoder->decode($data, $contentType); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @param object|string $object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @throws DeserializerLogicException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @throws DeserializerRuntimeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @return object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  |     public function denormalize($object, array $data, DenormalizerContextInterface $context = null, string $path = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  |         return $this->denormalizer->denormalize($object, $data, $context, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  |