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

api-platform / core / 5650127293

pending completion
5650127293

push

github

web-flow
fix: don't implement deprecated CacheableSupportsMethodInterface with Symfony 6.3+ (#5696)

* fix: don't implement deprecated CacheableSupportsMethodInterface

* fix: a check, and add tests

* fix ApiGatewayNormalizerTest

* more fixes

* fix more tests

* fix lowest

* only trigger the deprecation for Symfony 6.3

167 of 167 new or added lines in 23 files covered. (100.0%)

10865 of 18368 relevant lines covered (59.15%)

19.9 hits per line

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

59.09
/src/JsonApi/Serializer/EntrypointNormalizer.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\JsonApi\Serializer;
15

16
use ApiPlatform\Api\Entrypoint;
17
use ApiPlatform\Api\IriConverterInterface;
18
use ApiPlatform\Api\UrlGeneratorInterface;
19
use ApiPlatform\Exception\InvalidArgumentException;
20
use ApiPlatform\Metadata\CollectionOperationInterface;
21
use ApiPlatform\Metadata\HttpOperation;
22
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
23
use ApiPlatform\Serializer\CacheableSupportsMethodInterface;
24
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
25
use Symfony\Component\Serializer\Serializer;
26

27
/**
28
 * Normalizes the API entrypoint.
29
 *
30
 * @author Amrouche Hamza <hamza.simperfit@gmail.com>
31
 * @author Kévin Dunglas <dunglas@gmail.com>
32
 */
33
final class EntrypointNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
34
{
35
    public const FORMAT = 'jsonapi';
36

37
    public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, private readonly IriConverterInterface $iriConverter, private readonly UrlGeneratorInterface $urlGenerator)
38
    {
39
    }
58✔
40

41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
45
    {
46
        $entrypoint = ['links' => ['self' => $this->urlGenerator->generate('api_entrypoint', [], UrlGeneratorInterface::ABS_URL)]];
2✔
47

48
        foreach ($object->getResourceNameCollection() as $resourceClass) {
2✔
49
            $resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
2✔
50

51
            foreach ($resourceMetadata as $resource) {
2✔
52
                foreach ($resource->getOperations() as $operation) {
2✔
53
                    if (!$operation instanceof CollectionOperationInterface || ($operation instanceof HttpOperation && $operation->getUriVariables())) {
2✔
54
                        continue;
2✔
55
                    }
56

57
                    try {
58
                        $iri = $this->iriConverter->getIriFromResource($resourceClass, UrlGeneratorInterface::ABS_URL, $operation); // @phpstan-ignore-line phpstan issue as type is CollectionOperationInterface & Operation
2✔
59
                        $entrypoint['links'][lcfirst($resource->getShortName())] = $iri;
2✔
60
                    } catch (InvalidArgumentException) {
×
61
                        // Ignore resources without GET operations
62
                    }
63
                }
64
            }
65
        }
66

67
        return $entrypoint;
2✔
68
    }
69

70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
74
    {
75
        return self::FORMAT === $format && $data instanceof Entrypoint;
2✔
76
    }
77

78
    public function getSupportedTypes($format): array
79
    {
80
        return self::FORMAT === $format ? [Entrypoint::class => true] : [];
44✔
81
    }
82

83
    public function hasCacheableSupportsMethod(): bool
84
    {
85
        if (method_exists(Serializer::class, 'getSupportedTypes')) {
×
86
            trigger_deprecation(
×
87
                'api-platform/core',
×
88
                '3.1',
×
89
                'The "%s()" method is deprecated, use "getSupportedTypes()" instead.',
×
90
                __METHOD__
×
91
            );
×
92
        }
93

94
        return true;
×
95
    }
96
}
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

© 2026 Coveralls, Inc