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

api-platform / core / 17723449516

15 Sep 2025 05:52AM UTC coverage: 0.0% (-22.6%) from 22.578%
17723449516

Pull #7383

github

web-flow
Merge fa5b61e35 into 949c3c975
Pull Request #7383: fix(metadata): compute isWritable during updates

0 of 6 new or added lines in 4 files covered. (0.0%)

11356 existing lines in 371 files now uncovered.

0 of 48868 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/Symfony/Routing/ApiLoader.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\Symfony\Routing;
15

16
use ApiPlatform\Metadata\Exception\RuntimeException;
17
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
18
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
19
use ApiPlatform\OpenApi\Attributes\Webhook;
20
use Symfony\Component\Config\FileLocator;
21
use Symfony\Component\Config\Loader\Loader;
22
use Symfony\Component\Config\Resource\DirectoryResource;
23
use Symfony\Component\DependencyInjection\ContainerInterface;
24
use Symfony\Component\HttpKernel\KernelInterface;
25
use Symfony\Component\Routing\Loader\XmlFileLoader;
26
use Symfony\Component\Routing\Route;
27
use Symfony\Component\Routing\RouteCollection;
28

29
/**
30
 * Loads Resources.
31
 *
32
 * @author Kévin Dunglas <dunglas@gmail.com>
33
 */
34
final class ApiLoader extends Loader
35
{
36
    public const DEFAULT_ACTION_PATTERN = 'api_platform.action.';
37

38
    private readonly XmlFileLoader $fileLoader;
39

40
    public function __construct(KernelInterface $kernel, private readonly ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, private readonly ContainerInterface $container, private readonly array $formats, private readonly array $resourceClassDirectories = [], private readonly bool $graphqlEnabled = false, private readonly bool $entrypointEnabled = true, public readonly bool $docsEnabled = true, private readonly bool $graphiQlEnabled = false)
41
    {
42
        /** @var string[]|string $paths */
UNCOV
43
        $paths = $kernel->locateResource('@ApiPlatformBundle/Resources/config/routing');
×
UNCOV
44
        $this->fileLoader = new XmlFileLoader(new FileLocator($paths));
×
45
    }
46

47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function load(mixed $data, ?string $type = null): RouteCollection
51
    {
UNCOV
52
        $routeCollection = new RouteCollection();
×
UNCOV
53
        foreach ($this->resourceClassDirectories as $directory) {
×
UNCOV
54
            $routeCollection->addResource(new DirectoryResource($directory, '/\.php$/'));
×
55
        }
56

UNCOV
57
        $this->loadExternalFiles($routeCollection);
×
UNCOV
58
        foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) {
×
UNCOV
59
            foreach ($this->resourceMetadataFactory->create($resourceClass) as $resourceMetadata) {
×
UNCOV
60
                foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
×
UNCOV
61
                    if ($operation->getOpenapi() instanceof Webhook) {
×
62
                        continue;
×
63
                    }
64

UNCOV
65
                    if ($operation->getRouteName()) {
×
UNCOV
66
                        continue;
×
67
                    }
68

UNCOV
69
                    if (SkolemIriConverter::$skolemUriTemplate === $operation->getUriTemplate()) {
×
70
                        continue;
×
71
                    }
72

UNCOV
73
                    $path = ($operation->getRoutePrefix() ?? '').$operation->getUriTemplate();
×
UNCOV
74
                    foreach ($operation->getUriVariables() ?? [] as $parameterName => $link) {
×
UNCOV
75
                        if (!$expandedValue = $link->getExpandedValue()) {
×
UNCOV
76
                            continue;
×
77
                        }
78

UNCOV
79
                        $path = str_replace(\sprintf('{%s}', $parameterName), $expandedValue, $path);
×
80
                    }
81

82
                    // Within Symfony .{_format} is a special parameter but the rfc6570 specifies label expansion with a dot operator
UNCOV
83
                    if (str_ends_with($path, '{._format}')) {
×
UNCOV
84
                        $path = str_replace('{._format}', '.{_format}', $path);
×
85
                    }
86

UNCOV
87
                    if ($controller = $operation->getController()) {
×
UNCOV
88
                        $controllerId = explode('::', $controller, 2)[0];
×
UNCOV
89
                        if (!$this->container->has($controllerId)) {
×
UNCOV
90
                            throw new RuntimeException(\sprintf('Operation "%s" is defining an unknown service as controller "%s". Make sure it is properly registered in the dependency injection container.', $operationName, $controllerId));
×
91
                        }
92
                    }
93

UNCOV
94
                    $route = new Route(
×
UNCOV
95
                        $path,
×
UNCOV
96
                        [
×
UNCOV
97
                            '_controller' => $controller ?? 'api_platform.action.placeholder',
×
UNCOV
98
                            '_stateless' => $operation->getStateless(),
×
UNCOV
99
                            '_api_resource_class' => $resourceClass,
×
UNCOV
100
                            '_api_operation_name' => $operationName,
×
UNCOV
101
                        ] + ($operation->getDefaults() ?? []) + ['_format' => null],
×
UNCOV
102
                        $operation->getRequirements() ?? [],
×
UNCOV
103
                        $operation->getOptions() ?? [],
×
UNCOV
104
                        $operation->getHost() ?? '',
×
UNCOV
105
                        $operation->getSchemes() ?? [],
×
UNCOV
106
                        [$operation->getMethod() ?? 'GET'],
×
UNCOV
107
                        $operation->getCondition() ?? ''
×
UNCOV
108
                    );
×
109

UNCOV
110
                    $routeCollection->add($operationName, $route);
×
111
                }
112
            }
113
        }
114

UNCOV
115
        return $routeCollection;
×
116
    }
117

118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function supports(mixed $resource, ?string $type = null): bool
122
    {
UNCOV
123
        return 'api_platform' === $type;
×
124
    }
125

126
    /**
127
     * Load external files.
128
     */
129
    private function loadExternalFiles(RouteCollection $routeCollection): void
130
    {
UNCOV
131
        $routeCollection->addCollection($this->fileLoader->load('docs.xml'));
×
UNCOV
132
        $routeCollection->addCollection($this->fileLoader->load('genid.xml'));
×
UNCOV
133
        $routeCollection->addCollection($this->fileLoader->load('errors.xml'));
×
134

UNCOV
135
        if ($this->entrypointEnabled) {
×
UNCOV
136
            $routeCollection->addCollection($this->fileLoader->load('api.xml'));
×
137
        }
138

UNCOV
139
        if ($this->graphqlEnabled) {
×
UNCOV
140
            $graphqlCollection = $this->fileLoader->load('graphql/graphql.xml');
×
UNCOV
141
            $graphqlCollection->addDefaults(['_graphql' => true]);
×
UNCOV
142
            $routeCollection->addCollection($graphqlCollection);
×
143
        }
144

UNCOV
145
        if ($this->graphiQlEnabled) {
×
UNCOV
146
            $graphiQlCollection = $this->fileLoader->load('graphql/graphiql.xml');
×
UNCOV
147
            $graphiQlCollection->addDefaults(['_graphql' => true]);
×
UNCOV
148
            $routeCollection->addCollection($graphiQlCollection);
×
149
        }
150

UNCOV
151
        if (isset($this->formats['jsonld'])) {
×
UNCOV
152
            $routeCollection->addCollection($this->fileLoader->load('jsonld.xml'));
×
153
        }
154
    }
155
}
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