• 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

72.41
/src/Hydra/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\Hydra\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\Exception\OperationNotFoundException;
21
use ApiPlatform\Metadata\CollectionOperationInterface;
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 Kévin Dunglas <dunglas@gmail.com>
31
 */
32
final class EntrypointNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
33
{
34
    public const FORMAT = 'jsonld';
35

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

40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function normalize(mixed $object, string $format = null, array $context = []): array
44
    {
45
        $entrypoint = [
18✔
46
            '@context' => $this->urlGenerator->generate('api_jsonld_context', ['shortName' => 'Entrypoint']),
18✔
47
            '@id' => $this->urlGenerator->generate('api_entrypoint'),
18✔
48
            '@type' => 'Entrypoint',
18✔
49
        ];
18✔
50

51
        foreach ($object->getResourceNameCollection() as $resourceClass) {
18✔
52
            $resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
18✔
53

54
            foreach ($resourceMetadata as $resource) {
18✔
55
                if ($resource->getExtraProperties()['is_alternate_resource_metadata'] ?? false) {
18✔
56
                    continue;
14✔
57
                }
58

59
                foreach ($resource->getOperations() as $operation) {
18✔
60
                    $key = lcfirst($resource->getShortName());
18✔
61
                    if (!$operation instanceof CollectionOperationInterface || isset($entrypoint[$key])) {
18✔
62
                        continue;
14✔
63
                    }
64

65
                    try {
66
                        $entrypoint[$key] = $this->iriConverter->getIriFromResource($resourceClass, UrlGeneratorInterface::ABS_PATH, $operation); // @phpstan-ignore-line phpstan issue as type is CollectionOperationInterface & Operation
18✔
67
                    } catch (InvalidArgumentException|OperationNotFoundException) {
14✔
68
                        // Ignore resources without GET operations
69
                    }
70
                }
71
            }
72
        }
73

74
        ksort($entrypoint);
18✔
75

76
        return $entrypoint;
18✔
77
    }
78

79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
83
    {
84
        return self::FORMAT === $format && $data instanceof Entrypoint;
16✔
85
    }
86

87
    public function getSupportedTypes($format): array
88
    {
89
        return self::FORMAT === $format ? [Entrypoint::class => true] : [];
44✔
90
    }
91

92
    public function hasCacheableSupportsMethod(): bool
93
    {
94
        if (method_exists(Serializer::class, 'getSupportedTypes')) {
×
95
            trigger_deprecation(
×
96
                'api-platform/core',
×
97
                '3.1',
×
98
                'The "%s()" method is deprecated, use "getSupportedTypes()" instead.',
×
99
                __METHOD__
×
100
            );
×
101
        }
102

103
        return true;
×
104
    }
105
}
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