Skip to content
Snippets Groups Projects
Commit 5be64496 authored by Jack Robertson's avatar Jack Robertson
Browse files

upgrade symfony serializer to version 7

The CustomSerializer class was made final, so the CustomReferencedNormalizer
class must be updated to use composition over inheritance
parent c2e602f1
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
], ],
"require": { "require": {
"php": ">=8.1", "php": ">=8.1",
"symfony/serializer": "^6.0", "symfony/serializer": "^7.0",
"paragonie/random_compat": "*" "paragonie/random_compat": "*"
}, },
"require-dev": { "require-dev": {
......
...@@ -155,10 +155,11 @@ class Search ...@@ -155,10 +155,11 @@ class Search
private function initializeSerializer(): void private function initializeSerializer(): void
{ {
if (!static::$serializer instanceof OrderedSerializer) { if (!static::$serializer instanceof OrderedSerializer) {
$customNormalizer = new CustomNormalizer();
static::$serializer = new OrderedSerializer( static::$serializer = new OrderedSerializer(
[ [
new CustomReferencedNormalizer(), new CustomReferencedNormalizer($customNormalizer),
new CustomNormalizer(), $customNormalizer,
] ]
); );
} }
......
...@@ -12,34 +12,56 @@ ...@@ -12,34 +12,56 @@
namespace ONGR\ElasticsearchDSL\Serializer\Normalizer; namespace ONGR\ElasticsearchDSL\Serializer\Normalizer;
use Symfony\Component\Serializer\Normalizer\CustomNormalizer; 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. * Normalizer used with referenced normalized objects.
*/ */
class CustomReferencedNormalizer extends CustomNormalizer class CustomReferencedNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
{ {
private array $references = []; private array $references = [];
/** public function __construct(private readonly CustomNormalizer $customNormalizer)
* {@inheritdoc} {
*/ }
public function normalize( public function normalize(
mixed $object, mixed $object,
string $format = null, string $format = null,
array $context = [] array $context = []
): array|bool|string|int|float|null|\ArrayObject { ): array|bool|string|int|float|null|\ArrayObject {
$object->setReferences($this->references); $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()); $this->references = array_merge($this->references, $object->getReferences());
return $data; return $data;
} }
/** public function supportsNormalization(mixed $data, $format = null, array $context = []): bool
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null): bool
{ {
return $data instanceof AbstractNormalizable; 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);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment