• 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/Bundle/DependencyInjection/ApiPlatformExtension.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\Bundle\DependencyInjection;
15

16
use ApiPlatform\Doctrine\Odm\Extension\AggregationCollectionExtensionInterface;
17
use ApiPlatform\Doctrine\Odm\Extension\AggregationItemExtensionInterface;
18
use ApiPlatform\Doctrine\Odm\Filter\AbstractFilter as DoctrineMongoDbOdmAbstractFilter;
19
use ApiPlatform\Doctrine\Odm\State\LinksHandlerInterface as OdmLinksHandlerInterface;
20
use ApiPlatform\Doctrine\Orm\Extension\EagerLoadingExtension;
21
use ApiPlatform\Doctrine\Orm\Extension\FilterEagerLoadingExtension;
22
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface as DoctrineQueryCollectionExtensionInterface;
23
use ApiPlatform\Doctrine\Orm\Extension\QueryItemExtensionInterface;
24
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter as DoctrineOrmAbstractFilter;
25
use ApiPlatform\Doctrine\Orm\State\LinksHandlerInterface as OrmLinksHandlerInterface;
26
use ApiPlatform\Elasticsearch\Extension\RequestBodySearchCollectionExtensionInterface;
27
use ApiPlatform\GraphQl\Error\ErrorHandlerInterface;
28
use ApiPlatform\GraphQl\Executor;
29
use ApiPlatform\GraphQl\Resolver\MutationResolverInterface;
30
use ApiPlatform\GraphQl\Resolver\QueryCollectionResolverInterface;
31
use ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface;
32
use ApiPlatform\GraphQl\Type\Definition\TypeInterface as GraphQlTypeInterface;
33
use ApiPlatform\Metadata\ApiResource;
34
use ApiPlatform\Metadata\FilterInterface;
35
use ApiPlatform\Metadata\UriVariableTransformerInterface;
36
use ApiPlatform\Metadata\UrlGeneratorInterface;
37
use ApiPlatform\OpenApi\Model\Tag;
38
use ApiPlatform\RamseyUuid\Serializer\UuidDenormalizer;
39
use ApiPlatform\State\ApiResource\Error;
40
use ApiPlatform\State\ParameterProviderInterface;
41
use ApiPlatform\State\ProcessorInterface;
42
use ApiPlatform\State\ProviderInterface;
43
use ApiPlatform\Symfony\Validator\Metadata\Property\Restriction\PropertySchemaRestrictionMetadataInterface;
44
use ApiPlatform\Symfony\Validator\ValidationGroupsGeneratorInterface;
45
use ApiPlatform\Validator\Exception\ValidationException;
46
use Doctrine\Persistence\ManagerRegistry;
47
use PHPStan\PhpDocParser\Parser\PhpDocParser;
48
use Ramsey\Uuid\Uuid;
49
use Symfony\Component\Config\FileLocator;
50
use Symfony\Component\Config\Resource\DirectoryResource;
51
use Symfony\Component\DependencyInjection\ContainerBuilder;
52
use Symfony\Component\DependencyInjection\Definition;
53
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
54
use Symfony\Component\DependencyInjection\Extension\Extension;
55
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
56
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
57
use Symfony\Component\DependencyInjection\Reference;
58
use Symfony\Component\Finder\Finder;
59
use Symfony\Component\HttpClient\ScopingHttpClient;
60
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
61
use Symfony\Component\Uid\AbstractUid;
62
use Symfony\Component\Validator\Validator\ValidatorInterface;
63
use Symfony\Component\Yaml\Yaml;
64
use Twig\Environment;
65

66
/**
67
 * The extension of this bundle.
68
 *
69
 * @author Kévin Dunglas <dunglas@gmail.com>
70
 */
71
final class ApiPlatformExtension extends Extension implements PrependExtensionInterface
72
{
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function prepend(ContainerBuilder $container): void
77
    {
UNCOV
78
        if (isset($container->getExtensions()['framework'])) {
×
UNCOV
79
            $container->prependExtensionConfig('framework', [
×
UNCOV
80
                'serializer' => [
×
UNCOV
81
                    'enabled' => true,
×
UNCOV
82
                ],
×
UNCOV
83
            ]);
×
UNCOV
84
            $container->prependExtensionConfig('framework', [
×
UNCOV
85
                'property_info' => [
×
UNCOV
86
                    'enabled' => true,
×
UNCOV
87
                ],
×
UNCOV
88
            ]);
×
89
        }
UNCOV
90
        if (isset($container->getExtensions()['lexik_jwt_authentication'])) {
×
91
            $container->prependExtensionConfig('lexik_jwt_authentication', [
×
92
                'api_platform' => [
×
93
                    'enabled' => true,
×
94
                ],
×
95
            ]);
×
96
        }
97
    }
98

99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function load(array $configs, ContainerBuilder $container): void
103
    {
UNCOV
104
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
×
105

UNCOV
106
        $configuration = new Configuration();
×
UNCOV
107
        $config = $this->processConfiguration($configuration, $configs);
×
UNCOV
108
        $container->setParameter('api_platform.use_symfony_listeners', $config['use_symfony_listeners']);
×
109

UNCOV
110
        $formats = $this->getFormats($config['formats']);
×
UNCOV
111
        $patchFormats = $this->getFormats($config['patch_formats']);
×
UNCOV
112
        $errorFormats = $this->getFormats($config['error_formats']);
×
UNCOV
113
        $docsFormats = $this->getFormats($config['docs_formats']);
×
UNCOV
114
        if (!$config['enable_docs']) {
×
115
            // JSON-LD documentation format is mandatory, even if documentation is disabled.
116
            $docsFormats = isset($formats['jsonld']) ? ['jsonld' => ['application/ld+json']] : [];
×
117
            // If documentation is disabled, the Hydra documentation for all the resources is hidden by default.
118
            if (!isset($config['defaults']['hideHydraOperation']) && !isset($config['defaults']['hide_hydra_operation'])) {
×
119
                $config['defaults']['hideHydraOperation'] = true;
×
120
            }
121
        }
UNCOV
122
        $jsonSchemaFormats = $config['jsonschema_formats'];
×
123

UNCOV
124
        if (!$jsonSchemaFormats) {
×
UNCOV
125
            foreach (array_merge(array_keys($formats), array_keys($errorFormats)) as $f) {
×
126
                // Distinct JSON-based formats must have names that start with 'json'
UNCOV
127
                if (str_starts_with($f, 'json')) {
×
UNCOV
128
                    $jsonSchemaFormats[$f] = true;
×
129
                }
130
            }
131
        }
132

UNCOV
133
        if (!isset($errorFormats['json'])) {
×
UNCOV
134
            $errorFormats['json'] = ['application/problem+json', 'application/json'];
×
135
        }
136

UNCOV
137
        if (!isset($errorFormats['jsonproblem'])) {
×
138
            $errorFormats['jsonproblem'] = ['application/problem+json'];
×
139
        }
140

UNCOV
141
        if (isset($formats['jsonapi']) && !isset($patchFormats['jsonapi'])) {
×
UNCOV
142
            $patchFormats['jsonapi'] = ['application/vnd.api+json'];
×
143
        }
144

UNCOV
145
        $this->registerCommonConfiguration($container, $config, $loader, $formats, $patchFormats, $errorFormats, $docsFormats, $jsonSchemaFormats);
×
UNCOV
146
        $this->registerMetadataConfiguration($container, $config, $loader);
×
UNCOV
147
        $this->registerOAuthConfiguration($container, $config);
×
UNCOV
148
        $this->registerOpenApiConfiguration($container, $config, $loader);
×
UNCOV
149
        $this->registerSwaggerConfiguration($container, $config, $loader);
×
UNCOV
150
        $this->registerJsonApiConfiguration($formats, $loader, $config);
×
UNCOV
151
        $this->registerJsonLdHydraConfiguration($container, $formats, $loader, $config);
×
UNCOV
152
        $this->registerJsonHalConfiguration($formats, $loader);
×
UNCOV
153
        $this->registerJsonProblemConfiguration($errorFormats, $loader);
×
UNCOV
154
        $this->registerGraphQlConfiguration($container, $config, $loader);
×
UNCOV
155
        $this->registerCacheConfiguration($container);
×
UNCOV
156
        $this->registerDoctrineOrmConfiguration($container, $config, $loader);
×
UNCOV
157
        $this->registerDoctrineMongoDbOdmConfiguration($container, $config, $loader);
×
UNCOV
158
        $this->registerHttpCacheConfiguration($container, $config, $loader);
×
UNCOV
159
        $this->registerValidatorConfiguration($container, $config, $loader);
×
UNCOV
160
        $this->registerDataCollectorConfiguration($container, $config, $loader);
×
UNCOV
161
        $this->registerMercureConfiguration($container, $config, $loader);
×
UNCOV
162
        $this->registerMessengerConfiguration($container, $config, $loader);
×
UNCOV
163
        $this->registerElasticsearchConfiguration($container, $config, $loader);
×
UNCOV
164
        $this->registerSecurityConfiguration($container, $config, $loader);
×
UNCOV
165
        $this->registerMakerConfiguration($container, $config, $loader);
×
UNCOV
166
        $this->registerArgumentResolverConfiguration($loader);
×
UNCOV
167
        $this->registerLinkSecurityConfiguration($loader, $config);
×
168

UNCOV
169
        $container->registerForAutoconfiguration(FilterInterface::class)
×
UNCOV
170
            ->addTag('api_platform.filter');
×
UNCOV
171
        $container->registerForAutoconfiguration(ProviderInterface::class)
×
UNCOV
172
            ->addTag('api_platform.state_provider');
×
UNCOV
173
        $container->registerForAutoconfiguration(ProcessorInterface::class)
×
UNCOV
174
            ->addTag('api_platform.state_processor');
×
UNCOV
175
        $container->registerForAutoconfiguration(UriVariableTransformerInterface::class)
×
UNCOV
176
            ->addTag('api_platform.uri_variables.transformer');
×
UNCOV
177
        $container->registerForAutoconfiguration(ParameterProviderInterface::class)
×
UNCOV
178
            ->addTag('api_platform.parameter_provider');
×
179

UNCOV
180
        if (!$container->has('api_platform.state.item_provider')) {
×
181
            $container->setAlias('api_platform.state.item_provider', 'api_platform.state_provider.object');
×
182
        }
183
    }
184

185
    private function registerCommonConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader, array $formats, array $patchFormats, array $errorFormats, array $docsFormats, array $jsonSchemaFormats): void
186
    {
UNCOV
187
        $loader->load('state/state.xml');
×
UNCOV
188
        $loader->load('symfony/symfony.xml');
×
UNCOV
189
        $loader->load('api.xml');
×
UNCOV
190
        $loader->load('filter.xml');
×
191

UNCOV
192
        if (class_exists(UuidDenormalizer::class) && class_exists(Uuid::class)) {
×
UNCOV
193
            $loader->load('ramsey_uuid.xml');
×
194
        }
195

UNCOV
196
        if (class_exists(AbstractUid::class)) {
×
UNCOV
197
            $loader->load('symfony/uid.xml');
×
198
        }
199

UNCOV
200
        $defaultContext = ['hydra_prefix' => $config['serializer']['hydra_prefix']] + ($container->hasParameter('serializer.default_context') ? $container->getParameter('serializer.default_context') : []);
×
201

UNCOV
202
        $container->setParameter('api_platform.serializer.default_context', $defaultContext);
×
UNCOV
203
        if (!$container->hasParameter('serializer.default_context')) {
×
UNCOV
204
            $container->setParameter('serializer.default_context', $container->getParameter('api_platform.serializer.default_context'));
×
205
        }
UNCOV
206
        if ($config['use_symfony_listeners']) {
×
UNCOV
207
            $loader->load('symfony/events.xml');
×
208
        } else {
UNCOV
209
            $loader->load('symfony/controller.xml');
×
UNCOV
210
            $loader->load('state/provider.xml');
×
UNCOV
211
            $loader->load('state/processor.xml');
×
212
        }
UNCOV
213
        $loader->load('state/parameter_provider.xml');
×
214

UNCOV
215
        $container->setParameter('api_platform.enable_entrypoint', $config['enable_entrypoint']);
×
UNCOV
216
        $container->setParameter('api_platform.enable_docs', $config['enable_docs']);
×
UNCOV
217
        $container->setParameter('api_platform.title', $config['title']);
×
UNCOV
218
        $container->setParameter('api_platform.description', $config['description']);
×
UNCOV
219
        $container->setParameter('api_platform.version', $config['version']);
×
UNCOV
220
        $container->setParameter('api_platform.show_webby', $config['show_webby']);
×
UNCOV
221
        $container->setParameter('api_platform.url_generation_strategy', $config['defaults']['url_generation_strategy'] ?? UrlGeneratorInterface::ABS_PATH);
×
UNCOV
222
        $container->setParameter('api_platform.exception_to_status', $config['exception_to_status']);
×
UNCOV
223
        $container->setParameter('api_platform.formats', $formats);
×
UNCOV
224
        $container->setParameter('api_platform.patch_formats', $patchFormats);
×
UNCOV
225
        $container->setParameter('api_platform.error_formats', $errorFormats);
×
UNCOV
226
        $container->setParameter('api_platform.docs_formats', $docsFormats);
×
UNCOV
227
        $container->setParameter('api_platform.jsonschema_formats', $jsonSchemaFormats);
×
UNCOV
228
        $container->setParameter('api_platform.eager_loading.enabled', $this->isConfigEnabled($container, $config['eager_loading']));
×
UNCOV
229
        $container->setParameter('api_platform.eager_loading.max_joins', $config['eager_loading']['max_joins']);
×
UNCOV
230
        $container->setParameter('api_platform.eager_loading.fetch_partial', $config['eager_loading']['fetch_partial']);
×
UNCOV
231
        $container->setParameter('api_platform.eager_loading.force_eager', $config['eager_loading']['force_eager']);
×
UNCOV
232
        $container->setParameter('api_platform.collection.exists_parameter_name', $config['collection']['exists_parameter_name']);
×
UNCOV
233
        $container->setParameter('api_platform.collection.order', $config['collection']['order']);
×
UNCOV
234
        $container->setParameter('api_platform.collection.order_parameter_name', $config['collection']['order_parameter_name']);
×
UNCOV
235
        $container->setParameter('api_platform.collection.order_nulls_comparison', $config['collection']['order_nulls_comparison']);
×
UNCOV
236
        $container->setParameter('api_platform.collection.pagination.enabled', $config['defaults']['pagination_enabled'] ?? true);
×
UNCOV
237
        $container->setParameter('api_platform.collection.pagination.partial', $config['defaults']['pagination_partial'] ?? false);
×
UNCOV
238
        $container->setParameter('api_platform.collection.pagination.client_enabled', $config['defaults']['pagination_client_enabled'] ?? false);
×
UNCOV
239
        $container->setParameter('api_platform.collection.pagination.client_items_per_page', $config['defaults']['pagination_client_items_per_page'] ?? false);
×
UNCOV
240
        $container->setParameter('api_platform.collection.pagination.client_partial', $config['defaults']['pagination_client_partial'] ?? false);
×
UNCOV
241
        $container->setParameter('api_platform.collection.pagination.items_per_page', $config['defaults']['pagination_items_per_page'] ?? 30);
×
UNCOV
242
        $container->setParameter('api_platform.collection.pagination.maximum_items_per_page', $config['defaults']['pagination_maximum_items_per_page'] ?? null);
×
UNCOV
243
        $container->setParameter('api_platform.collection.pagination.page_parameter_name', $config['defaults']['pagination_page_parameter_name'] ?? $config['collection']['pagination']['page_parameter_name']);
×
UNCOV
244
        $container->setParameter('api_platform.collection.pagination.enabled_parameter_name', $config['defaults']['pagination_enabled_parameter_name'] ?? $config['collection']['pagination']['enabled_parameter_name']);
×
UNCOV
245
        $container->setParameter('api_platform.collection.pagination.items_per_page_parameter_name', $config['defaults']['pagination_items_per_page_parameter_name'] ?? $config['collection']['pagination']['items_per_page_parameter_name']);
×
UNCOV
246
        $container->setParameter('api_platform.collection.pagination.partial_parameter_name', $config['defaults']['pagination_partial_parameter_name'] ?? $config['collection']['pagination']['partial_parameter_name']);
×
UNCOV
247
        $container->setParameter('api_platform.collection.pagination', $this->getPaginationDefaults($config['defaults'] ?? [], $config['collection']['pagination']));
×
UNCOV
248
        $container->setParameter('api_platform.handle_symfony_errors', $config['handle_symfony_errors'] ?? false);
×
UNCOV
249
        $container->setParameter('api_platform.http_cache.etag', $config['defaults']['cache_headers']['etag'] ?? true);
×
UNCOV
250
        $container->setParameter('api_platform.http_cache.max_age', $config['defaults']['cache_headers']['max_age'] ?? null);
×
UNCOV
251
        $container->setParameter('api_platform.http_cache.shared_max_age', $config['defaults']['cache_headers']['shared_max_age'] ?? null);
×
UNCOV
252
        $container->setParameter('api_platform.http_cache.vary', $config['defaults']['cache_headers']['vary'] ?? ['Accept']);
×
UNCOV
253
        $container->setParameter('api_platform.http_cache.public', $config['defaults']['cache_headers']['public'] ?? $config['http_cache']['public']);
×
UNCOV
254
        $container->setParameter('api_platform.http_cache.invalidation.max_header_length', $config['defaults']['cache_headers']['invalidation']['max_header_length'] ?? $config['http_cache']['invalidation']['max_header_length']);
×
UNCOV
255
        $container->setParameter('api_platform.http_cache.invalidation.xkey.glue', $config['defaults']['cache_headers']['invalidation']['xkey']['glue'] ?? $config['http_cache']['invalidation']['xkey']['glue']);
×
256

UNCOV
257
        $container->setAlias('api_platform.path_segment_name_generator', $config['path_segment_name_generator']);
×
UNCOV
258
        $container->setAlias('api_platform.inflector', $config['inflector']);
×
259

UNCOV
260
        if ($config['name_converter']) {
×
UNCOV
261
            $container->setAlias('api_platform.name_converter', $config['name_converter']);
×
262
        }
UNCOV
263
        $container->setParameter('api_platform.asset_package', $config['asset_package']);
×
UNCOV
264
        $container->setParameter('api_platform.defaults', $this->normalizeDefaults($config['defaults'] ?? []));
×
265

UNCOV
266
        if ($container->getParameter('kernel.debug')) {
×
UNCOV
267
            $container->removeDefinition('api_platform.serializer.mapping.cache_class_metadata_factory');
×
268
        }
269
    }
270

271
    /**
272
     * This method will be removed in 3.0 when "defaults" will be the regular configuration path for the pagination.
273
     */
274
    private function getPaginationDefaults(array $defaults, array $collectionPaginationConfiguration): array
275
    {
UNCOV
276
        $paginationOptions = [];
×
277

UNCOV
278
        foreach ($defaults as $key => $value) {
×
UNCOV
279
            if (!str_starts_with($key, 'pagination_')) {
×
UNCOV
280
                continue;
×
281
            }
282

UNCOV
283
            $paginationOptions[str_replace('pagination_', '', $key)] = $value;
×
284
        }
285

UNCOV
286
        return array_merge($collectionPaginationConfiguration, $paginationOptions);
×
287
    }
288

289
    private function normalizeDefaults(array $defaults): array
290
    {
UNCOV
291
        $normalizedDefaults = ['extra_properties' => $defaults['extra_properties'] ?? []];
×
UNCOV
292
        unset($defaults['extra_properties']);
×
293

UNCOV
294
        $rc = new \ReflectionClass(ApiResource::class);
×
UNCOV
295
        $publicProperties = [];
×
UNCOV
296
        foreach ($rc->getConstructor()->getParameters() as $param) {
×
UNCOV
297
            $publicProperties[$param->getName()] = true;
×
298
        }
299

UNCOV
300
        $nameConverter = new CamelCaseToSnakeCaseNameConverter();
×
UNCOV
301
        foreach ($defaults as $option => $value) {
×
UNCOV
302
            if (isset($publicProperties[$nameConverter->denormalize($option)])) {
×
UNCOV
303
                $normalizedDefaults[$option] = $value;
×
304

UNCOV
305
                continue;
×
306
            }
307

308
            $normalizedDefaults['extra_properties'][$option] = $value;
×
309
        }
310

UNCOV
311
        return $normalizedDefaults;
×
312
    }
313

314
    private function registerMetadataConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
315
    {
UNCOV
316
        [$xmlResources, $yamlResources] = $this->getResourcesToWatch($container, $config);
×
317

UNCOV
318
        $container->setParameter('api_platform.class_name_resources', $this->getClassNameResources());
×
319

UNCOV
320
        $loader->load('metadata/resource_name.xml');
×
UNCOV
321
        $loader->load('metadata/property_name.xml');
×
322

UNCOV
323
        if (!empty($config['resource_class_directories'])) {
×
324
            $container->setParameter('api_platform.resource_class_directories', array_merge(
×
325
                $config['resource_class_directories'],
×
326
                $container->getParameter('api_platform.resource_class_directories')
×
327
            ));
×
328
        }
329

330
        // V3 metadata
UNCOV
331
        $loader->load('metadata/xml.xml');
×
UNCOV
332
        $loader->load('metadata/links.xml');
×
UNCOV
333
        $loader->load('metadata/property.xml');
×
UNCOV
334
        $loader->load('metadata/resource.xml');
×
UNCOV
335
        $loader->load('metadata/operation.xml');
×
336

UNCOV
337
        $container->getDefinition('api_platform.metadata.resource_extractor.xml')->replaceArgument(0, $xmlResources);
×
UNCOV
338
        $container->getDefinition('api_platform.metadata.property_extractor.xml')->replaceArgument(0, $xmlResources);
×
339

UNCOV
340
        if (class_exists(PhpDocParser::class)) {
×
UNCOV
341
            $loader->load('metadata/php_doc.xml');
×
342
        }
343

UNCOV
344
        if (class_exists(Yaml::class)) {
×
UNCOV
345
            $loader->load('metadata/yaml.xml');
×
UNCOV
346
            $container->getDefinition('api_platform.metadata.resource_extractor.yaml')->replaceArgument(0, $yamlResources);
×
UNCOV
347
            $container->getDefinition('api_platform.metadata.property_extractor.yaml')->replaceArgument(0, $yamlResources);
×
348
        }
349
    }
350

351
    private function getClassNameResources(): array
352
    {
UNCOV
353
        return [
×
UNCOV
354
            Error::class,
×
UNCOV
355
            ValidationException::class,
×
UNCOV
356
        ];
×
357
    }
358

359
    private function getBundlesResourcesPaths(ContainerBuilder $container, array $config): array
360
    {
UNCOV
361
        $bundlesResourcesPaths = [];
×
362

UNCOV
363
        foreach ($container->getParameter('kernel.bundles_metadata') as $bundle) {
×
UNCOV
364
            $dirname = $bundle['path'];
×
UNCOV
365
            $paths = [
×
UNCOV
366
                "$dirname/ApiResource",
×
UNCOV
367
                "$dirname/src/ApiResource",
×
UNCOV
368
            ];
×
UNCOV
369
            foreach (['.yaml', '.yml', '.xml', ''] as $extension) {
×
UNCOV
370
                $paths[] = "$dirname/Resources/config/api_resources$extension";
×
UNCOV
371
                $paths[] = "$dirname/config/api_resources$extension";
×
372
            }
UNCOV
373
            if ($this->isConfigEnabled($container, $config['doctrine'])) {
×
UNCOV
374
                $paths[] = "$dirname/Entity";
×
UNCOV
375
                $paths[] = "$dirname/src/Entity";
×
376
            }
UNCOV
377
            if ($this->isConfigEnabled($container, $config['doctrine_mongodb_odm'])) {
×
378
                $paths[] = "$dirname/Document";
×
379
                $paths[] = "$dirname/src/Document";
×
380
            }
381

UNCOV
382
            foreach ($paths as $path) {
×
UNCOV
383
                if ($container->fileExists($path, false)) {
×
UNCOV
384
                    $bundlesResourcesPaths[] = $path;
×
385
                }
386
            }
387
        }
388

UNCOV
389
        return $bundlesResourcesPaths;
×
390
    }
391

392
    private function getResourcesToWatch(ContainerBuilder $container, array $config): array
393
    {
UNCOV
394
        $paths = array_unique(array_merge($this->getBundlesResourcesPaths($container, $config), $config['mapping']['paths']));
×
395

UNCOV
396
        if (!$config['mapping']['paths']) {
×
397
            $projectDir = $container->getParameter('kernel.project_dir');
×
398
            foreach (["$projectDir/config/api_platform", "$projectDir/src/ApiResource"] as $dir) {
×
399
                if (is_dir($dir)) {
×
400
                    $paths[] = $dir;
×
401
                }
402
            }
403

404
            if ($this->isConfigEnabled($container, $config['doctrine']) && is_dir($doctrinePath = "$projectDir/src/Entity")) {
×
405
                $paths[] = $doctrinePath;
×
406
            }
407

408
            if ($this->isConfigEnabled($container, $config['doctrine_mongodb_odm']) && is_dir($documentPath = "$projectDir/src/Document")) {
×
409
                $paths[] = $documentPath;
×
410
            }
411
        }
412

UNCOV
413
        $resources = ['yml' => [], 'xml' => [], 'dir' => []];
×
414

UNCOV
415
        foreach ($paths as $path) {
×
UNCOV
416
            if (is_dir($path)) {
×
UNCOV
417
                foreach (Finder::create()->followLinks()->files()->in($path)->name('/\.(xml|ya?ml)$/')->sortByName() as $file) {
×
UNCOV
418
                    $resources['yaml' === ($extension = $file->getExtension()) ? 'yml' : $extension][] = $file->getRealPath();
×
419
                }
420

UNCOV
421
                $resources['dir'][] = $path;
×
UNCOV
422
                $container->addResource(new DirectoryResource($path, '/\.(xml|ya?ml|php)$/'));
×
423

UNCOV
424
                continue;
×
425
            }
426

427
            if ($container->fileExists($path, false)) {
×
428
                if (!preg_match('/\.(xml|ya?ml)$/', (string) $path, $matches)) {
×
429
                    throw new RuntimeException(\sprintf('Unsupported mapping type in "%s", supported types are XML & YAML.', $path));
×
430
                }
431

432
                $resources['yaml' === $matches[1] ? 'yml' : $matches[1]][] = $path;
×
433

434
                continue;
×
435
            }
436

437
            throw new RuntimeException(\sprintf('Could not open file or directory "%s".', $path));
×
438
        }
439

UNCOV
440
        $container->setParameter('api_platform.resource_class_directories', $resources['dir']);
×
441

UNCOV
442
        return [$resources['xml'], $resources['yml']];
×
443
    }
444

445
    private function registerOAuthConfiguration(ContainerBuilder $container, array $config): void
446
    {
UNCOV
447
        if (!$config['oauth']) {
×
448
            return;
×
449
        }
450

UNCOV
451
        $container->setParameter('api_platform.oauth.enabled', $this->isConfigEnabled($container, $config['oauth']));
×
UNCOV
452
        $container->setParameter('api_platform.oauth.clientId', $config['oauth']['clientId']);
×
UNCOV
453
        $container->setParameter('api_platform.oauth.clientSecret', $config['oauth']['clientSecret']);
×
UNCOV
454
        $container->setParameter('api_platform.oauth.type', $config['oauth']['type']);
×
UNCOV
455
        $container->setParameter('api_platform.oauth.flow', $config['oauth']['flow']);
×
UNCOV
456
        $container->setParameter('api_platform.oauth.tokenUrl', $config['oauth']['tokenUrl']);
×
UNCOV
457
        $container->setParameter('api_platform.oauth.authorizationUrl', $config['oauth']['authorizationUrl']);
×
UNCOV
458
        $container->setParameter('api_platform.oauth.refreshUrl', $config['oauth']['refreshUrl']);
×
UNCOV
459
        $container->setParameter('api_platform.oauth.scopes', $config['oauth']['scopes']);
×
UNCOV
460
        $container->setParameter('api_platform.oauth.pkce', $config['oauth']['pkce']);
×
461
    }
462

463
    /**
464
     * Registers the Swagger, ReDoc and Swagger UI configuration.
465
     */
466
    private function registerSwaggerConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
467
    {
UNCOV
468
        foreach (array_keys($config['swagger']['api_keys']) as $keyName) {
×
UNCOV
469
            if (!preg_match('/^[a-zA-Z0-9._-]+$/', $keyName)) {
×
470
                throw new RuntimeException(\sprintf('The swagger api_keys key "%s" is not valid, it should match "^[a-zA-Z0-9._-]+$"', $keyName));
×
471
            }
472
        }
473

UNCOV
474
        $container->setParameter('api_platform.swagger.versions', $config['swagger']['versions']);
×
475

UNCOV
476
        if (!$config['enable_swagger'] && $config['enable_swagger_ui']) {
×
477
            throw new RuntimeException('You can not enable the Swagger UI without enabling Swagger, fix this by enabling swagger via the configuration "enable_swagger: true".');
×
478
        }
479

UNCOV
480
        if (!$config['enable_swagger']) {
×
481
            return;
×
482
        }
483

UNCOV
484
        $loader->load('openapi.xml');
×
485

UNCOV
486
        if (class_exists(Yaml::class)) {
×
UNCOV
487
            $loader->load('openapi/yaml.xml');
×
488
        }
489

UNCOV
490
        $loader->load('swagger_ui.xml');
×
491

UNCOV
492
        if ($config['use_symfony_listeners']) {
×
UNCOV
493
            $loader->load('symfony/swagger_ui.xml');
×
494
        }
495

UNCOV
496
        if ($config['enable_swagger_ui']) {
×
UNCOV
497
            $loader->load('state/swagger_ui.xml');
×
498
        }
499

UNCOV
500
        if (!$config['enable_swagger_ui'] && !$config['enable_re_doc']) {
×
501
            // Remove the listener but keep the controller to allow customizing the path of the UI
502
            $container->removeDefinition('api_platform.swagger.listener.ui');
×
503
        }
504

UNCOV
505
        $container->setParameter('api_platform.enable_swagger_ui', $config['enable_swagger_ui']);
×
UNCOV
506
        $container->setParameter('api_platform.enable_re_doc', $config['enable_re_doc']);
×
UNCOV
507
        $container->setParameter('api_platform.swagger.api_keys', $config['swagger']['api_keys']);
×
UNCOV
508
        $container->setParameter('api_platform.swagger.persist_authorization', $config['swagger']['persist_authorization']);
×
UNCOV
509
        $container->setParameter('api_platform.swagger.http_auth', $config['swagger']['http_auth']);
×
UNCOV
510
        if ($config['openapi']['swagger_ui_extra_configuration'] && $config['swagger']['swagger_ui_extra_configuration']) {
×
511
            throw new RuntimeException('You can not set "swagger_ui_extra_configuration" twice - in "openapi" and "swagger" section.');
×
512
        }
UNCOV
513
        $container->setParameter('api_platform.swagger_ui.extra_configuration', $config['openapi']['swagger_ui_extra_configuration'] ?: $config['swagger']['swagger_ui_extra_configuration']);
×
514
    }
515

516
    private function registerJsonApiConfiguration(array $formats, XmlFileLoader $loader, array $config): void
517
    {
UNCOV
518
        if (!isset($formats['jsonapi'])) {
×
519
            return;
×
520
        }
521

UNCOV
522
        $loader->load('jsonapi.xml');
×
UNCOV
523
        $loader->load('state/jsonapi.xml');
×
524
    }
525

526
    private function registerJsonLdHydraConfiguration(ContainerBuilder $container, array $formats, XmlFileLoader $loader, array $config): void
527
    {
UNCOV
528
        if (!isset($formats['jsonld'])) {
×
529
            return;
×
530
        }
531

UNCOV
532
        if ($config['use_symfony_listeners']) {
×
UNCOV
533
            $loader->load('symfony/jsonld.xml');
×
534
        } else {
UNCOV
535
            $loader->load('state/jsonld.xml');
×
536
        }
537

UNCOV
538
        $loader->load('state/hydra.xml');
×
UNCOV
539
        $loader->load('jsonld.xml');
×
UNCOV
540
        $loader->load('hydra.xml');
×
541

UNCOV
542
        if (!$container->has('api_platform.json_schema.schema_factory')) {
×
543
            $container->removeDefinition('api_platform.hydra.json_schema.schema_factory');
×
544
        }
545
    }
546

547
    private function registerJsonHalConfiguration(array $formats, XmlFileLoader $loader): void
548
    {
UNCOV
549
        if (!isset($formats['jsonhal'])) {
×
550
            return;
×
551
        }
552

UNCOV
553
        $loader->load('hal.xml');
×
554
    }
555

556
    private function registerJsonProblemConfiguration(array $errorFormats, XmlFileLoader $loader): void
557
    {
UNCOV
558
        if (!isset($errorFormats['jsonproblem'])) {
×
559
            return;
×
560
        }
561

UNCOV
562
        $loader->load('problem.xml');
×
563
    }
564

565
    private function registerGraphQlConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
566
    {
UNCOV
567
        $enabled = $this->isConfigEnabled($container, $config['graphql']);
×
UNCOV
568
        $graphqlIntrospectionEnabled = $enabled && $this->isConfigEnabled($container, $config['graphql']['introspection']);
×
UNCOV
569
        $graphiqlEnabled = $enabled && $this->isConfigEnabled($container, $config['graphql']['graphiql']);
×
UNCOV
570
        $maxQueryDepth = (int) $config['graphql']['max_query_depth'];
×
UNCOV
571
        $maxQueryComplexity = (int) $config['graphql']['max_query_complexity'];
×
572

UNCOV
573
        $container->setParameter('api_platform.graphql.enabled', $enabled);
×
UNCOV
574
        $container->setParameter('api_platform.graphql.max_query_depth', $maxQueryDepth);
×
UNCOV
575
        $container->setParameter('api_platform.graphql.max_query_complexity', $maxQueryComplexity);
×
UNCOV
576
        $container->setParameter('api_platform.graphql.introspection.enabled', $graphqlIntrospectionEnabled);
×
UNCOV
577
        $container->setParameter('api_platform.graphql.graphiql.enabled', $graphiqlEnabled);
×
UNCOV
578
        $container->setParameter('api_platform.graphql.collection.pagination', $config['graphql']['collection']['pagination']);
×
579

UNCOV
580
        if (!$enabled) {
×
581
            return;
×
582
        }
583

UNCOV
584
        if (!class_exists(Executor::class)) {
×
585
            throw new \RuntimeException('Graphql is enabled but not installed, run: composer require "api-platform/graphql".');
×
586
        }
587

UNCOV
588
        $container->setParameter('api_platform.graphql.default_ide', $config['graphql']['default_ide']);
×
UNCOV
589
        $container->setParameter('api_platform.graphql.nesting_separator', $config['graphql']['nesting_separator']);
×
590

UNCOV
591
        $loader->load('graphql.xml');
×
592

593
        // @phpstan-ignore-next-line because PHPStan uses the container of the test env cache and in test the parameter kernel.bundles always contains the key TwigBundle
UNCOV
594
        if (!class_exists(Environment::class) || !isset($container->getParameter('kernel.bundles')['TwigBundle'])) {
×
595
            if ($graphiqlEnabled) {
×
596
                throw new RuntimeException(\sprintf('GraphiQL interfaces depend on Twig. Please activate TwigBundle for the %s environnement or disable GraphiQL.', $container->getParameter('kernel.environment')));
×
597
            }
598
            $container->removeDefinition('api_platform.graphql.action.graphiql');
×
599
        }
600

UNCOV
601
        $container->registerForAutoconfiguration(QueryItemResolverInterface::class)
×
UNCOV
602
            ->addTag('api_platform.graphql.resolver');
×
UNCOV
603
        $container->registerForAutoconfiguration(QueryCollectionResolverInterface::class)
×
UNCOV
604
            ->addTag('api_platform.graphql.resolver');
×
UNCOV
605
        $container->registerForAutoconfiguration(MutationResolverInterface::class)
×
UNCOV
606
            ->addTag('api_platform.graphql.resolver');
×
UNCOV
607
        $container->registerForAutoconfiguration(GraphQlTypeInterface::class)
×
UNCOV
608
            ->addTag('api_platform.graphql.type');
×
UNCOV
609
        $container->registerForAutoconfiguration(ErrorHandlerInterface::class)
×
UNCOV
610
            ->addTag('api_platform.graphql.error_handler');
×
611
    }
612

613
    private function registerCacheConfiguration(ContainerBuilder $container): void
614
    {
UNCOV
615
        if (!$container->hasParameter('kernel.debug') || !$container->getParameter('kernel.debug')) {
×
616
            $container->removeDefinition('api_platform.cache_warmer.cache_pool_clearer');
×
617
        }
618
    }
619

620
    private function registerDoctrineOrmConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
621
    {
UNCOV
622
        if (!$this->isConfigEnabled($container, $config['doctrine'])) {
×
623
            return;
×
624
        }
625

626
        // For older versions of doctrine bridge this allows autoconfiguration for filters
UNCOV
627
        if (!$container->has(ManagerRegistry::class)) {
×
UNCOV
628
            $container->setAlias(ManagerRegistry::class, 'doctrine');
×
629
        }
630

UNCOV
631
        $container->registerForAutoconfiguration(QueryItemExtensionInterface::class)
×
UNCOV
632
            ->addTag('api_platform.doctrine.orm.query_extension.item');
×
UNCOV
633
        $container->registerForAutoconfiguration(DoctrineQueryCollectionExtensionInterface::class)
×
UNCOV
634
            ->addTag('api_platform.doctrine.orm.query_extension.collection');
×
UNCOV
635
        $container->registerForAutoconfiguration(DoctrineOrmAbstractFilter::class);
×
636

UNCOV
637
        $container->registerForAutoconfiguration(OrmLinksHandlerInterface::class)
×
UNCOV
638
            ->addTag('api_platform.doctrine.orm.links_handler');
×
639

UNCOV
640
        $loader->load('doctrine_orm.xml');
×
641

UNCOV
642
        if ($this->isConfigEnabled($container, $config['eager_loading'])) {
×
UNCOV
643
            return;
×
644
        }
645

646
        $container->removeAlias(EagerLoadingExtension::class);
×
647
        $container->removeDefinition('api_platform.doctrine.orm.query_extension.eager_loading');
×
648
        $container->removeAlias(FilterEagerLoadingExtension::class);
×
649
        $container->removeDefinition('api_platform.doctrine.orm.query_extension.filter_eager_loading');
×
650
    }
651

652
    private function registerDoctrineMongoDbOdmConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
653
    {
UNCOV
654
        if (!$this->isConfigEnabled($container, $config['doctrine_mongodb_odm'])) {
×
UNCOV
655
            return;
×
656
        }
657

658
        $container->registerForAutoconfiguration(AggregationItemExtensionInterface::class)
×
659
            ->addTag('api_platform.doctrine_mongodb.odm.aggregation_extension.item');
×
660
        $container->registerForAutoconfiguration(AggregationCollectionExtensionInterface::class)
×
661
            ->addTag('api_platform.doctrine_mongodb.odm.aggregation_extension.collection');
×
662
        $container->registerForAutoconfiguration(DoctrineMongoDbOdmAbstractFilter::class)
×
663
            ->setBindings(['$managerRegistry' => new Reference('doctrine_mongodb')]);
×
664
        $container->registerForAutoconfiguration(OdmLinksHandlerInterface::class)
×
665
            ->addTag('api_platform.doctrine.odm.links_handler');
×
666

667
        $loader->load('doctrine_mongodb_odm.xml');
×
668
    }
669

670
    private function registerHttpCacheConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
671
    {
UNCOV
672
        $loader->load('http_cache.xml');
×
673

UNCOV
674
        if (!$this->isConfigEnabled($container, $config['http_cache']['invalidation'])) {
×
675
            return;
×
676
        }
677

UNCOV
678
        if ($this->isConfigEnabled($container, $config['doctrine'])) {
×
UNCOV
679
            $loader->load('doctrine_orm_http_cache_purger.xml');
×
680
        }
681

UNCOV
682
        $loader->load('state/http_cache_purger.xml');
×
UNCOV
683
        $loader->load('http_cache_purger.xml');
×
684

UNCOV
685
        foreach ($config['http_cache']['invalidation']['scoped_clients'] as $client) {
×
686
            $definition = $container->getDefinition($client);
×
687
            $definition->addTag('api_platform.http_cache.http_client');
×
688
        }
689

UNCOV
690
        if (!($urls = $config['http_cache']['invalidation']['urls'])) {
×
UNCOV
691
            $urls = $config['http_cache']['invalidation']['varnish_urls'];
×
692
        }
693

UNCOV
694
        foreach ($urls as $key => $url) {
×
695
            $definition = new Definition(ScopingHttpClient::class, [new Reference('http_client'), $url, ['base_uri' => $url] + $config['http_cache']['invalidation']['request_options']]);
×
696
            $definition->setFactory([ScopingHttpClient::class, 'forBaseUri']);
×
697
            $definition->addTag('api_platform.http_cache.http_client');
×
698
            $container->setDefinition('api_platform.invalidation_http_client.'.$key, $definition);
×
699
        }
700

UNCOV
701
        $serviceName = $config['http_cache']['invalidation']['purger'];
×
702

UNCOV
703
        if (!$container->hasDefinition('api_platform.http_cache.purger')) {
×
UNCOV
704
            $container->setAlias('api_platform.http_cache.purger', $serviceName);
×
705
        }
706
    }
707

708
    /**
709
     * Normalizes the format from config to the one accepted by Symfony HttpFoundation.
710
     */
711
    private function getFormats(array $configFormats): array
712
    {
UNCOV
713
        $formats = [];
×
UNCOV
714
        foreach ($configFormats as $format => $value) {
×
UNCOV
715
            foreach ($value['mime_types'] as $mimeType) {
×
UNCOV
716
                $formats[$format][] = $mimeType;
×
717
            }
718
        }
719

UNCOV
720
        return $formats;
×
721
    }
722

723
    private function registerValidatorConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
724
    {
UNCOV
725
        if (interface_exists(ValidatorInterface::class)) {
×
UNCOV
726
            $loader->load('metadata/validator.xml');
×
UNCOV
727
            $loader->load('validator/validator.xml');
×
728

UNCOV
729
            if ($this->isConfigEnabled($container, $config['graphql'])) {
×
UNCOV
730
                $loader->load('graphql/validator.xml');
×
731
            }
732

UNCOV
733
            $loader->load($config['use_symfony_listeners'] ? 'validator/events.xml' : 'validator/state.xml');
×
734

UNCOV
735
            $container->registerForAutoconfiguration(ValidationGroupsGeneratorInterface::class)
×
UNCOV
736
                ->addTag('api_platform.validation_groups_generator');
×
UNCOV
737
            $container->registerForAutoconfiguration(PropertySchemaRestrictionMetadataInterface::class)
×
UNCOV
738
                ->addTag('api_platform.metadata.property_schema_restriction');
×
739
        }
740

UNCOV
741
        if (!$config['validator']) {
×
742
            return;
×
743
        }
744

UNCOV
745
        $container->setParameter('api_platform.validator.serialize_payload_fields', $config['validator']['serialize_payload_fields']);
×
UNCOV
746
        $container->setParameter('api_platform.validator.query_parameter_validation', $config['validator']['query_parameter_validation']);
×
747

UNCOV
748
        if (!$config['validator']['query_parameter_validation']) {
×
749
            $container->removeDefinition('api_platform.listener.view.validate_query_parameters');
×
750
            $container->removeDefinition('api_platform.validator.query_parameter_validator');
×
751
            $container->removeDefinition('api_platform.symfony.parameter_validator');
×
752
        }
753
    }
754

755
    private function registerDataCollectorConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
756
    {
UNCOV
757
        if (!$config['enable_profiler']) {
×
758
            return;
×
759
        }
760

UNCOV
761
        $loader->load('data_collector.xml');
×
762

UNCOV
763
        if ($container->hasParameter('kernel.debug') && $container->getParameter('kernel.debug')) {
×
UNCOV
764
            $loader->load('debug.xml');
×
765
        }
766
    }
767

768
    private function registerMercureConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
769
    {
UNCOV
770
        if (!$this->isConfigEnabled($container, $config['mercure'])) {
×
771
            return;
×
772
        }
773

UNCOV
774
        $container->setParameter('api_platform.mercure.include_type', $config['mercure']['include_type']);
×
UNCOV
775
        $loader->load('state/mercure.xml');
×
776

UNCOV
777
        if ($this->isConfigEnabled($container, $config['doctrine'])) {
×
UNCOV
778
            $loader->load('doctrine_orm_mercure_publisher.xml');
×
779
        }
UNCOV
780
        if ($this->isConfigEnabled($container, $config['doctrine_mongodb_odm'])) {
×
781
            $loader->load('doctrine_odm_mercure_publisher.xml');
×
782
        }
783

UNCOV
784
        if ($this->isConfigEnabled($container, $config['graphql'])) {
×
UNCOV
785
            $loader->load('graphql_mercure.xml');
×
786
        }
787
    }
788

789
    private function registerMessengerConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
790
    {
UNCOV
791
        if (!$this->isConfigEnabled($container, $config['messenger'])) {
×
792
            return;
×
793
        }
794

UNCOV
795
        $loader->load('messenger.xml');
×
796
    }
797

798
    private function registerElasticsearchConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
799
    {
UNCOV
800
        $enabled = $this->isConfigEnabled($container, $config['elasticsearch']);
×
801

UNCOV
802
        $container->setParameter('api_platform.elasticsearch.enabled', $enabled);
×
803

UNCOV
804
        if (!$enabled) {
×
UNCOV
805
            return;
×
806
        }
807

808
        $clientClass = !class_exists(\Elasticsearch\Client::class)
×
809
            // ES v7
×
810
            ? \Elastic\Elasticsearch\Client::class
×
811
            // ES v8 and up
×
812
            : \Elasticsearch\Client::class;
×
813

814
        $clientDefinition = new Definition($clientClass);
×
815
        $container->setDefinition('api_platform.elasticsearch.client', $clientDefinition);
×
816
        $container->registerForAutoconfiguration(RequestBodySearchCollectionExtensionInterface::class)
×
817
            ->addTag('api_platform.elasticsearch.request_body_search_extension.collection');
×
818
        $container->setParameter('api_platform.elasticsearch.hosts', $config['elasticsearch']['hosts']);
×
819
        $loader->load('elasticsearch.xml');
×
820
    }
821

822
    private function registerSecurityConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
823
    {
824
        /** @var string[] $bundles */
UNCOV
825
        $bundles = $container->getParameter('kernel.bundles');
×
826

UNCOV
827
        if (!isset($bundles['SecurityBundle'])) {
×
828
            return;
×
829
        }
830

UNCOV
831
        $loader->load('security.xml');
×
832

UNCOV
833
        $loader->load('state/security.xml');
×
834

UNCOV
835
        if (interface_exists(ValidatorInterface::class)) {
×
UNCOV
836
            $loader->load('state/security_validator.xml');
×
837
        }
838

UNCOV
839
        if ($this->isConfigEnabled($container, $config['graphql'])) {
×
UNCOV
840
            $loader->load('graphql/security.xml');
×
841
        }
842
    }
843

844
    private function registerOpenApiConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
845
    {
UNCOV
846
        $container->setParameter('api_platform.openapi.termsOfService', $config['openapi']['termsOfService']);
×
UNCOV
847
        $container->setParameter('api_platform.openapi.contact.name', $config['openapi']['contact']['name']);
×
UNCOV
848
        $container->setParameter('api_platform.openapi.contact.url', $config['openapi']['contact']['url']);
×
UNCOV
849
        $container->setParameter('api_platform.openapi.contact.email', $config['openapi']['contact']['email']);
×
UNCOV
850
        $container->setParameter('api_platform.openapi.license.name', $config['openapi']['license']['name']);
×
UNCOV
851
        $container->setParameter('api_platform.openapi.license.url', $config['openapi']['license']['url']);
×
UNCOV
852
        $container->setParameter('api_platform.openapi.overrideResponses', $config['openapi']['overrideResponses']);
×
853

UNCOV
854
        $tags = [];
×
UNCOV
855
        foreach ($config['openapi']['tags'] as $tag) {
×
856
            $tags[] = new Tag($tag['name'], $tag['description'] ?? null);
×
857
        }
858

UNCOV
859
        $container->setParameter('api_platform.openapi.tags', $tags);
×
860

UNCOV
861
        $loader->load('json_schema.xml');
×
862
    }
863

864
    private function registerMakerConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
865
    {
UNCOV
866
        if (!$this->isConfigEnabled($container, $config['maker'])) {
×
867
            return;
×
868
        }
869

UNCOV
870
        $loader->load('maker.xml');
×
871
    }
872

873
    private function registerArgumentResolverConfiguration(XmlFileLoader $loader): void
874
    {
UNCOV
875
        $loader->load('argument_resolver.xml');
×
876
    }
877

878
    private function registerLinkSecurityConfiguration(XmlFileLoader $loader, array $config): void
879
    {
UNCOV
880
        if ($config['enable_link_security']) {
×
UNCOV
881
            $loader->load('link_security.xml');
×
882
        }
883
    }
884
}
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