| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Serializer\Normalizer; |
| 13 |
|
| 14 |
use Symfony\Component\Serializer\SerializerAwareInterface; |
| 15 |
use Symfony\Component\Serializer\SerializerAwareTrait; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
final class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface |
| 21 |
{ |
| 22 |
use ObjectToPopulateTrait; |
| 23 |
use SerializerAwareTrait; |
| 24 |
|
| 25 |
public function getSupportedTypes(?string $format): array |
| 26 |
{ |
| 27 |
return [ |
| 28 |
NormalizableInterface::class => true, |
| 29 |
DenormalizableInterface::class => true, |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null |
| 34 |
{ |
| 35 |
return $data->normalize($this->serializer, $format, $context); |
| 36 |
} |
| 37 |
|
| 38 |
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed |
| 39 |
{ |
| 40 |
$object = $this->extractObjectToPopulate($type, $context) ?? new $type(); |
| 41 |
$object->denormalize($this->serializer, $data, $format, $context); |
| 42 |
|
| 43 |
return $object; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool |
| 53 |
{ |
| 54 |
return $data instanceof NormalizableInterface; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool |
| 65 |
{ |
| 66 |
return is_subclass_of($type, DenormalizableInterface::class); |
| 67 |
} |
| 68 |
} |