• 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

54.55
/src/Hal/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\Hal\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\Operation;
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 = 'jsonhal';
35

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

40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function normalize(mixed $object, string $format = null, array $context = []): array
44
    {
45
        $entrypoint = ['_links' => ['self' => ['href' => $this->urlGenerator->generate('api_entrypoint')]]];
2✔
46

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

50
            foreach ($resourceMetadata as $resource) {
2✔
51
                foreach ($resource->getOperations() as $operation) {
2✔
52
                    /** @var Operation $operation */
53
                    if (!$operation instanceof CollectionOperationInterface) {
2✔
54
                        continue;
×
55
                    }
56

57
                    try {
58
                        $href = $this->iriConverter->getIriFromResource($operation->getClass(), UrlGeneratorInterface::ABS_PATH, $operation);
2✔
59
                        $entrypoint['_links'][lcfirst($operation->getShortName())]['href'] = $href;
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] : [];
30✔
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