diff --git a/composer.json b/composer.json index fe96a67f78a95002af0f38cfbcf0be0c4d0b5340..4604387ec57c530f10dfb71baff52ff4fe711ae3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": ">=8.1", - "symfony/serializer": "^6.0", + "symfony/serializer": "^7.0", "paragonie/random_compat": "*" }, "require-dev": { diff --git a/src/Search.php b/src/Search.php index a109a6a28fc9f2a4034dadd1f5148d0f1972858d..7bad863964fab544db8e8d241d5220a196cbf988 100644 --- a/src/Search.php +++ b/src/Search.php @@ -155,10 +155,11 @@ class Search private function initializeSerializer(): void { if (!static::$serializer instanceof OrderedSerializer) { + $customNormalizer = new CustomNormalizer(); static::$serializer = new OrderedSerializer( [ - new CustomReferencedNormalizer(), - new CustomNormalizer(), + new CustomReferencedNormalizer($customNormalizer), + $customNormalizer, ] ); } diff --git a/src/Serializer/Normalizer/CustomReferencedNormalizer.php b/src/Serializer/Normalizer/CustomReferencedNormalizer.php index abdf95d46a38ac9c11c34057a2e024b5cabfcc59..e891b19b23b6848e977b2f9dc4e40e1e56afad35 100644 --- a/src/Serializer/Normalizer/CustomReferencedNormalizer.php +++ b/src/Serializer/Normalizer/CustomReferencedNormalizer.php @@ -12,34 +12,56 @@ namespace ONGR\ElasticsearchDSL\Serializer\Normalizer; use Symfony\Component\Serializer\Normalizer\CustomNormalizer; +use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\SerializerAwareInterface; +use Symfony\Component\Serializer\SerializerInterface; /** * Normalizer used with referenced normalized objects. */ -class CustomReferencedNormalizer extends CustomNormalizer +class CustomReferencedNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface { private array $references = []; - /** - * {@inheritdoc} - */ + public function __construct(private readonly CustomNormalizer $customNormalizer) + { + } + public function normalize( mixed $object, string $format = null, array $context = [] ): array|bool|string|int|float|null|\ArrayObject { $object->setReferences($this->references); - $data = parent::normalize($object, $format, $context); + $data = $this->customNormalizer->normalize($object, $format, $context); $this->references = array_merge($this->references, $object->getReferences()); return $data; } - /** - * {@inheritdoc} - */ - public function supportsNormalization($data, $format = null): bool + public function supportsNormalization(mixed $data, $format = null, array $context = []): bool { return $data instanceof AbstractNormalizable; } + + public function getSupportedTypes(?string $format): array + { + return $this->customNormalizer->getSupportedTypes($format); + } + + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed + { + return $this->customNormalizer->denormalize($data, $type, $format, $context); + } + + public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool + { + return $this->customNormalizer->supportsDenormalization($data, $type, $format, $context); + } + + public function setSerializer(SerializerInterface $serializer): void + { + $this->customNormalizer->setSerializer($serializer); + } }