Debian Codegraph @

lib/3rdParty/composer/symfony/serializer/Normalizer/CustomNormalizer.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Serializer\Normalizer;
13
14 use Symfony\Component\Serializer\SerializerAwareInterface;
15 use Symfony\Component\Serializer\SerializerAwareTrait;
16
17 /**
18 * @author Jordi Boggiano <[email protected]>
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 * Checks if the given class implements the NormalizableInterface.
48 *
49 * @param mixed $data Data to normalize
50 * @param string|null $format The format being (de-)serialized from or into
51 */
52 public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
53 {
54 return $data instanceof NormalizableInterface;
55 }
56
57 /**
58 * Checks if the given class implements the DenormalizableInterface.
59 *
60 * @param mixed $data Data to denormalize from
61 * @param string $type The class to which the data should be denormalized
62 * @param string|null $format The format being deserialized from
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 }