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

api-platform / core / 9663895513

25 Jun 2024 02:01PM UTC coverage: 62.122% (-0.5%) from 62.637%
9663895513

push

github

web-flow
feat(laravel): laravel component (#5882)

* feat(laravel): laravel component

* try to skip laravel

* feat(jsonapi): component

* feat(laravel): json api support (needs review)

* work on relations

* relations (needs toMany) + skolem + IRI to resource

* links handler

* ulid

* validation

* slug post

* remove deprecations

* move classes

* fix tests

* fix tests metadata

* phpstan

* missing class

* fix laravel tests

* fix stan

33 of 77 new or added lines in 20 files covered. (42.86%)

140 existing lines in 15 files now uncovered.

10862 of 17485 relevant lines covered (62.12%)

59.64 hits per line

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

9.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\Documentation\Entrypoint;
17
use ApiPlatform\Metadata\CollectionOperationInterface;
18
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
19
use ApiPlatform\Metadata\HttpOperation;
20
use ApiPlatform\Metadata\IriConverterInterface;
21
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
22
use ApiPlatform\Metadata\UrlGeneratorInterface;
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
    }
352✔
40

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

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

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

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

UNCOV
67
        return $entrypoint;
×
68
    }
69

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

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

© 2025 Coveralls, Inc