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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 hits per line

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

100.0
/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\Documentation\Entrypoint;
17
use ApiPlatform\Metadata\CollectionOperationInterface;
18
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
19
use ApiPlatform\Metadata\IriConverterInterface;
20
use ApiPlatform\Metadata\Operation;
21
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
22
use ApiPlatform\Metadata\UrlGeneratorInterface;
23
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
24

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

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

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

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

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

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

65
        return $entrypoint;
3✔
66
    }
67

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

76
    public function getSupportedTypes($format): array
77
    {
78
        return self::FORMAT === $format ? [Entrypoint::class => true] : [];
1,047✔
79
    }
80
}
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