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

api-platform / core / 3713134090

pending completion
3713134090

Pull #5254

github

GitHub
Merge b2ec54b3c into ac711530f
Pull Request #5254: [OpenApi] Add ApiResource::openapi and deprecate openapiContext

197 of 197 new or added lines in 5 files covered. (100.0%)

10372 of 12438 relevant lines covered (83.39%)

11.97 hits per line

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

85.71
/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 Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
24
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
25

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

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

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

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

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

56
                    try {
57
                        $href = $this->iriConverter->getIriFromResource($operation->getClass(), UrlGeneratorInterface::ABS_PATH, $operation);
1✔
58
                        $entrypoint['_links'][lcfirst($operation->getShortName())]['href'] = $href;
1✔
59
                    } catch (InvalidArgumentException) {
×
60
                        // Ignore resources without GET operations
61
                    }
62
                }
63
            }
64
        }
65

66
        return $entrypoint;
1✔
67
    }
68

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

77
    public function hasCacheableSupportsMethod(): bool
78
    {
79
        return true;
14✔
80
    }
81
}
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