File manager - Edit - /var/www/payraty/helpdesk/vendor/handcraftedinthealps/elasticsearch-dsl/src/Serializer/Normalizer/CustomReferencedNormalizer.php
Back
<?php /* * This file is part of the ONGR package. * * (c) NFQ Technologies UAB <info@nfq.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ONGR\ElasticsearchDSL\Serializer\Normalizer; use Symfony\Component\Serializer\Normalizer\DenormalizableInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizableInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait; use Symfony\Component\Serializer\SerializerAwareInterface; use Symfony\Component\Serializer\SerializerAwareTrait; /** * Normalizer used with referenced normalized objects. * * Most parts are copy of * https://github.com/symfony/symfony/blob/7.2/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php * as @final in Symfony 7. */ class CustomReferencedNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface { use ObjectToPopulateTrait; use SerializerAwareTrait; /** * @var array */ private $references = []; public function getSupportedTypes(?string $format): array { return [ NormalizableInterface::class => true, DenormalizableInterface::class => true, ]; } /** * {@inheritdoc} */ public function normalize( $object, $format = null, array $context = [] ): array|string|int|float|bool|\ArrayObject|null { $object->setReferences($this->references); $data = $object->normalize($this->serializer, $format, $context); $this->references = array_merge($this->references, $object->getReferences()); return $data; } public function denormalize($data, $type, $format = null, array $context = []): mixed { $object = $this->extractObjectToPopulate($type, $context) ?? new $type(); $object->denormalize($this->serializer, $data, $format, $context); return $object; } /** * Checks if the given class implements the NormalizableInterface. * * @param mixed $data Data to normalize * @param string|null $format The format being (de-)serialized from or into */ public function supportsNormalization($data, $format = null, array $context = []): bool { return $data instanceof NormalizableInterface; } /** * Checks if the given class implements the DenormalizableInterface. * * @param mixed $data Data to denormalize from * @param string $type The class to which the data should be denormalized * @param string|null $format The format being deserialized from */ public function supportsDenormalization($data, $type, $format = null, array $context = []): bool { return is_subclass_of($type, DenormalizableInterface::class); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0 |
proxy
|
phpinfo
|
Settings