• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 15394724286

02 Jun 2025 02:19PM UTC coverage: 22.201% (+0.1%) from 22.062%
15394724286

push

github

soyuka
feat(elasticsearch): add support for v9 (#7180)

Co-authored-by: darthf1 <17253332+darthf1@users.noreply.github.com>

10888 of 49042 relevant lines covered (22.2%)

10.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Elasticsearch/Serializer/ItemNormalizer.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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
declare(strict_types=1);
13

14
namespace ApiPlatform\Elasticsearch\Serializer;
15

16
use Symfony\Component\Serializer\Exception\LogicException;
17
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
18
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
19
use Symfony\Component\Serializer\SerializerAwareInterface;
20
use Symfony\Component\Serializer\SerializerInterface;
21

22
/**
23
 * Item normalizer decorator that prevents {@see \ApiPlatform\Serializer\ItemNormalizer}
24
 * from taking over for the {@see DocumentNormalizer::FORMAT} format because of priorities.
25
 *
26
 * @experimental
27
 */
28
final class ItemNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
29
{
30
    public const FORMAT = 'elasticsearch';
31

32
    public function __construct(private readonly NormalizerInterface $decorated)
33
    {
34
    }
×
35

36
    /**
37
     * {@inheritdoc}
38
     *
39
     * @throws LogicException
40
     */
41
    public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
42
    {
43
        if (!$this->decorated instanceof DenormalizerInterface) {
×
44
            throw new LogicException(\sprintf('The decorated normalizer must be an instance of "%s".', DenormalizerInterface::class));
×
45
        }
46

47
        return $this->decorated->denormalize($data, $type, $format, $context);
×
48
    }
49

50
    /**
51
     * {@inheritdoc}
52
     *
53
     * @throws LogicException
54
     */
55
    public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
56
    {
57
        if (!$this->decorated instanceof DenormalizerInterface) {
×
58
            throw new LogicException(\sprintf('The decorated normalizer must be an instance of "%s".', DenormalizerInterface::class));
×
59
        }
60

61
        return DocumentNormalizer::FORMAT !== $format && $this->decorated->supportsDenormalization($data, $type, $format, $context);
×
62
    }
63

64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function normalize(mixed $object, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
68
    {
69
        return $this->decorated->normalize($object, $format, $context);
×
70
    }
71

72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
76
    {
77
        return DocumentNormalizer::FORMAT !== $format && $this->decorated->supportsNormalization($data, $format);
×
78
    }
79

80
    public function getSupportedTypes($format): array
81
    {
82
        return DocumentNormalizer::FORMAT !== $format ? $this->decorated->getSupportedTypes($format) : [];
×
83
    }
84

85
    /**
86
     * {@inheritdoc}
87
     *
88
     * @throws LogicException
89
     */
90
    public function setSerializer(SerializerInterface $serializer): void
91
    {
92
        if (!$this->decorated instanceof SerializerAwareInterface) {
×
93
            throw new LogicException(\sprintf('The decorated normalizer must be an instance of "%s".', SerializerAwareInterface::class));
×
94
        }
95

96
        $this->decorated->setSerializer($serializer);
×
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc