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

api-platform / core / 15023181448

14 May 2025 02:19PM UTC coverage: 0.0% (-8.4%) from 8.418%
15023181448

Pull #7139

github

web-flow
Merge 9f45709da into 1862d03b7
Pull Request #7139: refactor(symfony): remove obsolete option `validator.query-parameter-validation`

0 of 4 new or added lines in 1 file covered. (0.0%)

11266 existing lines in 366 files now uncovered.

0 of 50828 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 phpDocumentor\Reflection\DocBlockFactoryInterface;
48
use PHPStan\PhpDocParser\Parser\PhpDocParser;
49
use Ramsey\Uuid\Uuid;
50
use Symfony\Component\Config\FileLocator;
51
use Symfony\Component\Config\Resource\DirectoryResource;
52
use Symfony\Component\DependencyInjection\ChildDefinition;
53
use Symfony\Component\DependencyInjection\ContainerBuilder;
54
use Symfony\Component\DependencyInjection\Definition;
55
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
56
use Symfony\Component\DependencyInjection\Extension\Extension;
57
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
58
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
59
use Symfony\Component\DependencyInjection\Reference;
60
use Symfony\Component\Finder\Finder;
61
use Symfony\Component\HttpClient\ScopingHttpClient;
62
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
63
use Symfony\Component\Uid\AbstractUid;
64
use Symfony\Component\Validator\Validator\ValidatorInterface;
65
use Symfony\Component\Yaml\Yaml;
66
use Twig\Environment;
67

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

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

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

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

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

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

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

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

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

UNCOV
171
        $container->registerForAutoconfiguration(FilterInterface::class)
×
UNCOV
172
            ->addTag('api_platform.filter');
×
UNCOV
173
        $container->registerForAutoconfiguration(ProviderInterface::class)
×
UNCOV
174
            ->addTag('api_platform.state_provider');
×
UNCOV
175
        $container->registerForAutoconfiguration(ProcessorInterface::class)
×
UNCOV
176
            ->addTag('api_platform.state_processor');
×
UNCOV
177
        $container->registerForAutoconfiguration(UriVariableTransformerInterface::class)
×
UNCOV
178
            ->addTag('api_platform.uri_variables.transformer');
×
UNCOV
179
        $container->registerForAutoconfiguration(ParameterProviderInterface::class)
×
UNCOV
180
            ->addTag('api_platform.parameter_provider');
×
UNCOV
181
        $container->registerAttributeForAutoconfiguration(ApiResource::class, static function (ChildDefinition $definition): void {
×
182
            $definition->setAbstract(true)
×
183
                ->addTag('api_platform.resource')
×
184
                ->addTag('container.excluded', ['source' => 'by #[ApiResource] attribute']);
×
UNCOV
185
        });
×
186

UNCOV
187
        if (!$container->has('api_platform.state.item_provider')) {
×
188
            $container->setAlias('api_platform.state.item_provider', 'api_platform.state_provider.object');
×
189
        }
190
    }
191

192
    private function registerCommonConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader, array $formats, array $patchFormats, array $errorFormats, array $docsFormats, array $jsonSchemaFormats): void
193
    {
UNCOV
194
        $loader->load('state/state.xml');
×
UNCOV
195
        $loader->load('symfony/symfony.xml');
×
UNCOV
196
        $loader->load('api.xml');
×
UNCOV
197
        $loader->load('filter.xml');
×
198

UNCOV
199
        if (class_exists(UuidDenormalizer::class) && class_exists(Uuid::class)) {
×
UNCOV
200
            $loader->load('ramsey_uuid.xml');
×
201
        }
202

UNCOV
203
        if (class_exists(AbstractUid::class)) {
×
UNCOV
204
            $loader->load('symfony/uid.xml');
×
205
        }
206

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

UNCOV
209
        $container->setParameter('api_platform.serializer.default_context', $defaultContext);
×
UNCOV
210
        if (!$container->hasParameter('serializer.default_context')) {
×
UNCOV
211
            $container->setParameter('serializer.default_context', $container->getParameter('api_platform.serializer.default_context'));
×
212
        }
UNCOV
213
        if ($config['use_symfony_listeners']) {
×
214
            $loader->load('symfony/events.xml');
×
215
        } else {
UNCOV
216
            $loader->load('symfony/controller.xml');
×
UNCOV
217
            $loader->load('state/provider.xml');
×
UNCOV
218
            $loader->load('state/processor.xml');
×
219
        }
220

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

UNCOV
263
        $container->setAlias('api_platform.path_segment_name_generator', $config['path_segment_name_generator']);
×
UNCOV
264
        $container->setAlias('api_platform.inflector', $config['inflector']);
×
265

UNCOV
266
        if ($config['name_converter']) {
×
UNCOV
267
            $container->setAlias('api_platform.name_converter', $config['name_converter']);
×
268
        }
UNCOV
269
        $container->setParameter('api_platform.asset_package', $config['asset_package']);
×
UNCOV
270
        $container->setParameter('api_platform.defaults', $this->normalizeDefaults($config['defaults'] ?? []));
×
271

UNCOV
272
        if ($container->getParameter('kernel.debug')) {
×
UNCOV
273
            $container->removeDefinition('api_platform.serializer.mapping.cache_class_metadata_factory');
×
274
        }
275
    }
276

277
    /**
278
     * This method will be removed in 3.0 when "defaults" will be the regular configuration path for the pagination.
279
     */
280
    private function getPaginationDefaults(array $defaults, array $collectionPaginationConfiguration): array
281
    {
UNCOV
282
        $paginationOptions = [];
×
283

UNCOV
284
        foreach ($defaults as $key => $value) {
×
UNCOV
285
            if (!str_starts_with($key, 'pagination_')) {
×
UNCOV
286
                continue;
×
287
            }
288

UNCOV
289
            $paginationOptions[str_replace('pagination_', '', $key)] = $value;
×
290
        }
291

UNCOV
292
        return array_merge($collectionPaginationConfiguration, $paginationOptions);
×
293
    }
294

295
    private function normalizeDefaults(array $defaults): array
296
    {
UNCOV
297
        $normalizedDefaults = ['extra_properties' => $defaults['extra_properties'] ?? []];
×
UNCOV
298
        unset($defaults['extra_properties']);
×
299

UNCOV
300
        $rc = new \ReflectionClass(ApiResource::class);
×
UNCOV
301
        $publicProperties = [];
×
UNCOV
302
        foreach ($rc->getConstructor()->getParameters() as $param) {
×
UNCOV
303
            $publicProperties[$param->getName()] = true;
×
304
        }
305

UNCOV
306
        $nameConverter = new CamelCaseToSnakeCaseNameConverter();
×
UNCOV
307
        foreach ($defaults as $option => $value) {
×
UNCOV
308
            if (isset($publicProperties[$nameConverter->denormalize($option)])) {
×
UNCOV
309
                $normalizedDefaults[$option] = $value;
×
310

UNCOV
311
                continue;
×
312
            }
313

314
            $normalizedDefaults['extra_properties'][$option] = $value;
×
315
        }
316

UNCOV
317
        return $normalizedDefaults;
×
318
    }
319

320
    private function registerMetadataConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
321
    {
UNCOV
322
        [$xmlResources, $yamlResources] = $this->getResourcesToWatch($container, $config);
×
323

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

UNCOV
326
        $loader->load('metadata/resource_name.xml');
×
UNCOV
327
        $loader->load('metadata/property_name.xml');
×
328

UNCOV
329
        if (!empty($config['resource_class_directories'])) {
×
330
            $container->setParameter('api_platform.resource_class_directories', array_merge(
×
331
                $config['resource_class_directories'],
×
332
                $container->getParameter('api_platform.resource_class_directories')
×
333
            ));
×
334
        }
335

336
        // V3 metadata
UNCOV
337
        $loader->load('metadata/xml.xml');
×
UNCOV
338
        $loader->load('metadata/links.xml');
×
UNCOV
339
        $loader->load('metadata/property.xml');
×
UNCOV
340
        $loader->load('metadata/resource.xml');
×
UNCOV
341
        $loader->load('metadata/operation.xml');
×
342

UNCOV
343
        $container->getDefinition('api_platform.metadata.resource_extractor.xml')->replaceArgument(0, $xmlResources);
×
UNCOV
344
        $container->getDefinition('api_platform.metadata.property_extractor.xml')->replaceArgument(0, $xmlResources);
×
345

UNCOV
346
        if (class_exists(PhpDocParser::class) || interface_exists(DocBlockFactoryInterface::class)) {
×
UNCOV
347
            $loader->load('metadata/php_doc.xml');
×
348
        }
349

UNCOV
350
        if (class_exists(Yaml::class)) {
×
UNCOV
351
            $loader->load('metadata/yaml.xml');
×
UNCOV
352
            $container->getDefinition('api_platform.metadata.resource_extractor.yaml')->replaceArgument(0, $yamlResources);
×
UNCOV
353
            $container->getDefinition('api_platform.metadata.property_extractor.yaml')->replaceArgument(0, $yamlResources);
×
354
        }
355
    }
356

357
    private function getClassNameResources(): array
358
    {
UNCOV
359
        return [
×
UNCOV
360
            Error::class,
×
UNCOV
361
            ValidationException::class,
×
UNCOV
362
        ];
×
363
    }
364

365
    private function getBundlesResourcesPaths(ContainerBuilder $container, array $config): array
366
    {
UNCOV
367
        $bundlesResourcesPaths = [];
×
368

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

UNCOV
388
            foreach ($paths as $path) {
×
UNCOV
389
                if ($container->fileExists($path, false)) {
×
UNCOV
390
                    $bundlesResourcesPaths[] = $path;
×
391
                }
392
            }
393
        }
394

UNCOV
395
        return $bundlesResourcesPaths;
×
396
    }
397

398
    private function getResourcesToWatch(ContainerBuilder $container, array $config): array
399
    {
UNCOV
400
        $paths = array_unique(array_merge($this->getBundlesResourcesPaths($container, $config), $config['mapping']['paths']));
×
401

UNCOV
402
        if (!$config['mapping']['paths']) {
×
403
            $projectDir = $container->getParameter('kernel.project_dir');
×
404
            foreach (["$projectDir/config/api_platform", "$projectDir/src/ApiResource"] as $dir) {
×
405
                if (is_dir($dir)) {
×
406
                    $paths[] = $dir;
×
407
                }
408
            }
409

410
            if ($this->isConfigEnabled($container, $config['doctrine']) && is_dir($doctrinePath = "$projectDir/src/Entity")) {
×
411
                $paths[] = $doctrinePath;
×
412
            }
413

414
            if ($this->isConfigEnabled($container, $config['doctrine_mongodb_odm']) && is_dir($documentPath = "$projectDir/src/Document")) {
×
415
                $paths[] = $documentPath;
×
416
            }
417
        }
418

UNCOV
419
        $resources = ['yml' => [], 'xml' => [], 'dir' => []];
×
420

UNCOV
421
        foreach ($paths as $path) {
×
UNCOV
422
            if (is_dir($path)) {
×
UNCOV
423
                foreach (Finder::create()->followLinks()->files()->in($path)->name('/\.(xml|ya?ml)$/')->sortByName() as $file) {
×
UNCOV
424
                    $resources['yaml' === ($extension = $file->getExtension()) ? 'yml' : $extension][] = $file->getRealPath();
×
425
                }
426

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

UNCOV
430
                continue;
×
431
            }
432

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

438
                $resources['yaml' === $matches[1] ? 'yml' : $matches[1]][] = $path;
×
439

440
                continue;
×
441
            }
442

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

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

UNCOV
448
        return [$resources['xml'], $resources['yml']];
×
449
    }
450

451
    private function registerOAuthConfiguration(ContainerBuilder $container, array $config): void
452
    {
UNCOV
453
        if (!$config['oauth']) {
×
454
            return;
×
455
        }
456

UNCOV
457
        $container->setParameter('api_platform.oauth.enabled', $this->isConfigEnabled($container, $config['oauth']));
×
UNCOV
458
        $container->setParameter('api_platform.oauth.clientId', $config['oauth']['clientId']);
×
UNCOV
459
        $container->setParameter('api_platform.oauth.clientSecret', $config['oauth']['clientSecret']);
×
UNCOV
460
        $container->setParameter('api_platform.oauth.type', $config['oauth']['type']);
×
UNCOV
461
        $container->setParameter('api_platform.oauth.flow', $config['oauth']['flow']);
×
UNCOV
462
        $container->setParameter('api_platform.oauth.tokenUrl', $config['oauth']['tokenUrl']);
×
UNCOV
463
        $container->setParameter('api_platform.oauth.authorizationUrl', $config['oauth']['authorizationUrl']);
×
UNCOV
464
        $container->setParameter('api_platform.oauth.refreshUrl', $config['oauth']['refreshUrl']);
×
UNCOV
465
        $container->setParameter('api_platform.oauth.scopes', $config['oauth']['scopes']);
×
UNCOV
466
        $container->setParameter('api_platform.oauth.pkce', $config['oauth']['pkce']);
×
467

UNCOV
468
        if ($container->hasDefinition('api_platform.swagger_ui.action')) {
×
469
            $container->getDefinition('api_platform.swagger_ui.action')->setArgument(10, $config['oauth']['pkce']);
×
470
        }
471
    }
472

473
    /**
474
     * Registers the Swagger, ReDoc and Swagger UI configuration.
475
     */
476
    private function registerSwaggerConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
477
    {
UNCOV
478
        foreach (array_keys($config['swagger']['api_keys']) as $keyName) {
×
UNCOV
479
            if (!preg_match('/^[a-zA-Z0-9._-]+$/', $keyName)) {
×
480
                trigger_deprecation('api-platform/core', '3.1', \sprintf('The swagger api_keys key "%s" is not valid with OpenAPI 3.1 it should match "^[a-zA-Z0-9._-]+$"', $keyName));
×
481
            }
482
        }
483

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

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

UNCOV
490
        if (!$config['enable_swagger']) {
×
491
            return;
×
492
        }
493

UNCOV
494
        $loader->load('openapi.xml');
×
495

UNCOV
496
        if (class_exists(Yaml::class)) {
×
UNCOV
497
            $loader->load('openapi/yaml.xml');
×
498
        }
499

UNCOV
500
        $loader->load('swagger_ui.xml');
×
501

UNCOV
502
        if ($config['use_symfony_listeners']) {
×
503
            $loader->load('symfony/swagger_ui.xml');
×
504
        }
505

UNCOV
506
        if ($config['enable_swagger_ui']) {
×
UNCOV
507
            $loader->load('state/swagger_ui.xml');
×
508
        }
509

UNCOV
510
        if (!$config['enable_swagger_ui'] && !$config['enable_re_doc']) {
×
511
            // Remove the listener but keep the controller to allow customizing the path of the UI
512
            $container->removeDefinition('api_platform.swagger.listener.ui');
×
513
        }
514

UNCOV
515
        $container->setParameter('api_platform.enable_swagger_ui', $config['enable_swagger_ui']);
×
UNCOV
516
        $container->setParameter('api_platform.enable_re_doc', $config['enable_re_doc']);
×
UNCOV
517
        $container->setParameter('api_platform.swagger.api_keys', $config['swagger']['api_keys']);
×
UNCOV
518
        $container->setParameter('api_platform.swagger.persist_authorization', $config['swagger']['persist_authorization']);
×
UNCOV
519
        $container->setParameter('api_platform.swagger.http_auth', $config['swagger']['http_auth']);
×
UNCOV
520
        if ($config['openapi']['swagger_ui_extra_configuration'] && $config['swagger']['swagger_ui_extra_configuration']) {
×
521
            throw new RuntimeException('You can not set "swagger_ui_extra_configuration" twice - in "openapi" and "swagger" section.');
×
522
        }
UNCOV
523
        $container->setParameter('api_platform.swagger_ui.extra_configuration', $config['openapi']['swagger_ui_extra_configuration'] ?: $config['swagger']['swagger_ui_extra_configuration']);
×
524
    }
525

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

UNCOV
532
        $loader->load('jsonapi.xml');
×
UNCOV
533
        $loader->load('state/jsonapi.xml');
×
534
    }
535

536
    private function registerJsonLdHydraConfiguration(ContainerBuilder $container, array $formats, XmlFileLoader $loader, array $config): void
537
    {
UNCOV
538
        if (!isset($formats['jsonld'])) {
×
539
            return;
×
540
        }
541

UNCOV
542
        if ($config['use_symfony_listeners']) {
×
543
            $loader->load('symfony/jsonld.xml');
×
544
        } else {
UNCOV
545
            $loader->load('state/jsonld.xml');
×
546
        }
547

UNCOV
548
        $loader->load('state/hydra.xml');
×
UNCOV
549
        $loader->load('jsonld.xml');
×
UNCOV
550
        $loader->load('hydra.xml');
×
551

UNCOV
552
        if (!$container->has('api_platform.json_schema.schema_factory')) {
×
553
            $container->removeDefinition('api_platform.hydra.json_schema.schema_factory');
×
554
        }
555
    }
556

557
    private function registerJsonHalConfiguration(array $formats, XmlFileLoader $loader): void
558
    {
UNCOV
559
        if (!isset($formats['jsonhal'])) {
×
560
            return;
×
561
        }
562

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

566
    private function registerJsonProblemConfiguration(array $errorFormats, XmlFileLoader $loader): void
567
    {
UNCOV
568
        if (!isset($errorFormats['jsonproblem'])) {
×
569
            return;
×
570
        }
571

UNCOV
572
        $loader->load('problem.xml');
×
573
    }
574

575
    private function registerGraphQlConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
576
    {
UNCOV
577
        $enabled = $this->isConfigEnabled($container, $config['graphql']);
×
UNCOV
578
        $graphqlIntrospectionEnabled = $enabled && $this->isConfigEnabled($container, $config['graphql']['introspection']);
×
UNCOV
579
        $graphiqlEnabled = $enabled && $this->isConfigEnabled($container, $config['graphql']['graphiql']);
×
UNCOV
580
        $graphqlPlayGroundEnabled = $enabled && $this->isConfigEnabled($container, $config['graphql']['graphql_playground']);
×
UNCOV
581
        $maxQueryDepth = (int) $config['graphql']['max_query_depth'];
×
UNCOV
582
        $maxQueryComplexity = (int) $config['graphql']['max_query_complexity'];
×
UNCOV
583
        if ($graphqlPlayGroundEnabled) {
×
584
            trigger_deprecation('api-platform/core', '3.1', 'GraphQL Playground is deprecated and will be removed in API Platform 4.0. Only GraphiQL will be available in the future. Set api_platform.graphql.graphql_playground to false in the configuration to remove this deprecation.');
×
585
        }
586

UNCOV
587
        $container->setParameter('api_platform.graphql.enabled', $enabled);
×
UNCOV
588
        $container->setParameter('api_platform.graphql.max_query_depth', $maxQueryDepth);
×
UNCOV
589
        $container->setParameter('api_platform.graphql.max_query_complexity', $maxQueryComplexity);
×
UNCOV
590
        $container->setParameter('api_platform.graphql.introspection.enabled', $graphqlIntrospectionEnabled);
×
UNCOV
591
        $container->setParameter('api_platform.graphql.graphiql.enabled', $graphiqlEnabled);
×
UNCOV
592
        $container->setParameter('api_platform.graphql.graphql_playground.enabled', $graphqlPlayGroundEnabled);
×
UNCOV
593
        $container->setParameter('api_platform.graphql.collection.pagination', $config['graphql']['collection']['pagination']);
×
594

UNCOV
595
        if (!$enabled) {
×
596
            return;
×
597
        }
598

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

UNCOV
603
        $container->setParameter('api_platform.graphql.default_ide', $config['graphql']['default_ide']);
×
UNCOV
604
        $container->setParameter('api_platform.graphql.nesting_separator', $config['graphql']['nesting_separator']);
×
605

UNCOV
606
        $loader->load('graphql.xml');
×
607

608
        // @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
609
        if (!class_exists(Environment::class) || !isset($container->getParameter('kernel.bundles')['TwigBundle'])) {
×
610
            if ($graphiqlEnabled || $graphqlPlayGroundEnabled) {
×
611
                throw new RuntimeException(\sprintf('GraphiQL and GraphQL Playground interfaces depend on Twig. Please activate TwigBundle for the %s environnement or disable GraphiQL and GraphQL Playground.', $container->getParameter('kernel.environment')));
×
612
            }
613
            $container->removeDefinition('api_platform.graphql.action.graphiql');
×
614
            $container->removeDefinition('api_platform.graphql.action.graphql_playground');
×
615
        }
616

UNCOV
617
        $container->registerForAutoconfiguration(QueryItemResolverInterface::class)
×
UNCOV
618
            ->addTag('api_platform.graphql.resolver');
×
UNCOV
619
        $container->registerForAutoconfiguration(QueryCollectionResolverInterface::class)
×
UNCOV
620
            ->addTag('api_platform.graphql.resolver');
×
UNCOV
621
        $container->registerForAutoconfiguration(MutationResolverInterface::class)
×
UNCOV
622
            ->addTag('api_platform.graphql.resolver');
×
UNCOV
623
        $container->registerForAutoconfiguration(GraphQlTypeInterface::class)
×
UNCOV
624
            ->addTag('api_platform.graphql.type');
×
UNCOV
625
        $container->registerForAutoconfiguration(ErrorHandlerInterface::class)
×
UNCOV
626
            ->addTag('api_platform.graphql.error_handler');
×
627
    }
628

629
    private function registerCacheConfiguration(ContainerBuilder $container): void
630
    {
UNCOV
631
        if (!$container->hasParameter('kernel.debug') || !$container->getParameter('kernel.debug')) {
×
632
            $container->removeDefinition('api_platform.cache_warmer.cache_pool_clearer');
×
633
        }
634
    }
635

636
    private function registerDoctrineOrmConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
637
    {
UNCOV
638
        if (!$this->isConfigEnabled($container, $config['doctrine'])) {
×
639
            return;
×
640
        }
641

642
        // For older versions of doctrine bridge this allows autoconfiguration for filters
UNCOV
643
        if (!$container->has(ManagerRegistry::class)) {
×
UNCOV
644
            $container->setAlias(ManagerRegistry::class, 'doctrine');
×
645
        }
646

UNCOV
647
        $container->registerForAutoconfiguration(QueryItemExtensionInterface::class)
×
UNCOV
648
            ->addTag('api_platform.doctrine.orm.query_extension.item');
×
UNCOV
649
        $container->registerForAutoconfiguration(DoctrineQueryCollectionExtensionInterface::class)
×
UNCOV
650
            ->addTag('api_platform.doctrine.orm.query_extension.collection');
×
UNCOV
651
        $container->registerForAutoconfiguration(DoctrineOrmAbstractFilter::class);
×
652

UNCOV
653
        $container->registerForAutoconfiguration(OrmLinksHandlerInterface::class)
×
UNCOV
654
            ->addTag('api_platform.doctrine.orm.links_handler');
×
655

UNCOV
656
        $loader->load('doctrine_orm.xml');
×
657

UNCOV
658
        if ($this->isConfigEnabled($container, $config['eager_loading'])) {
×
UNCOV
659
            return;
×
660
        }
661

662
        $container->removeAlias(EagerLoadingExtension::class);
×
663
        $container->removeDefinition('api_platform.doctrine.orm.query_extension.eager_loading');
×
664
        $container->removeAlias(FilterEagerLoadingExtension::class);
×
665
        $container->removeDefinition('api_platform.doctrine.orm.query_extension.filter_eager_loading');
×
666
    }
667

668
    private function registerDoctrineMongoDbOdmConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
669
    {
UNCOV
670
        if (!$this->isConfigEnabled($container, $config['doctrine_mongodb_odm'])) {
×
UNCOV
671
            return;
×
672
        }
673

674
        $container->registerForAutoconfiguration(AggregationItemExtensionInterface::class)
×
675
            ->addTag('api_platform.doctrine_mongodb.odm.aggregation_extension.item');
×
676
        $container->registerForAutoconfiguration(AggregationCollectionExtensionInterface::class)
×
677
            ->addTag('api_platform.doctrine_mongodb.odm.aggregation_extension.collection');
×
678
        $container->registerForAutoconfiguration(DoctrineMongoDbOdmAbstractFilter::class)
×
679
            ->setBindings(['$managerRegistry' => new Reference('doctrine_mongodb')]);
×
680
        $container->registerForAutoconfiguration(OdmLinksHandlerInterface::class)
×
681
            ->addTag('api_platform.doctrine.odm.links_handler');
×
682

683
        $loader->load('doctrine_mongodb_odm.xml');
×
684
    }
685

686
    private function registerHttpCacheConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
687
    {
UNCOV
688
        $loader->load('http_cache.xml');
×
689

UNCOV
690
        if (!$this->isConfigEnabled($container, $config['http_cache']['invalidation'])) {
×
691
            return;
×
692
        }
693

UNCOV
694
        if ($this->isConfigEnabled($container, $config['doctrine'])) {
×
UNCOV
695
            $loader->load('doctrine_orm_http_cache_purger.xml');
×
696
        }
697

UNCOV
698
        $loader->load('state/http_cache_purger.xml');
×
UNCOV
699
        $loader->load('http_cache_purger.xml');
×
700

UNCOV
701
        foreach ($config['http_cache']['invalidation']['scoped_clients'] as $client) {
×
702
            $definition = $container->getDefinition($client);
×
703
            $definition->addTag('api_platform.http_cache.http_client');
×
704
        }
705

UNCOV
706
        if (!($urls = $config['http_cache']['invalidation']['urls'])) {
×
UNCOV
707
            $urls = $config['http_cache']['invalidation']['varnish_urls'];
×
708
        }
709

UNCOV
710
        foreach ($urls as $key => $url) {
×
711
            $definition = new Definition(ScopingHttpClient::class, [new Reference('http_client'), $url, ['base_uri' => $url] + $config['http_cache']['invalidation']['request_options']]);
×
712
            $definition->setFactory([ScopingHttpClient::class, 'forBaseUri']);
×
713
            $definition->addTag('api_platform.http_cache.http_client');
×
714
            $container->setDefinition('api_platform.invalidation_http_client.'.$key, $definition);
×
715
        }
716

UNCOV
717
        $serviceName = $config['http_cache']['invalidation']['purger'];
×
718

UNCOV
719
        if (!$container->hasDefinition('api_platform.http_cache.purger')) {
×
UNCOV
720
            $container->setAlias('api_platform.http_cache.purger', $serviceName);
×
721
        }
722
    }
723

724
    /**
725
     * Normalizes the format from config to the one accepted by Symfony HttpFoundation.
726
     */
727
    private function getFormats(array $configFormats): array
728
    {
UNCOV
729
        $formats = [];
×
UNCOV
730
        foreach ($configFormats as $format => $value) {
×
UNCOV
731
            foreach ($value['mime_types'] as $mimeType) {
×
UNCOV
732
                $formats[$format][] = $mimeType;
×
733
            }
734
        }
735

UNCOV
736
        return $formats;
×
737
    }
738

739
    private function registerValidatorConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
740
    {
UNCOV
741
        if (interface_exists(ValidatorInterface::class)) {
×
UNCOV
742
            $loader->load('metadata/validator.xml');
×
UNCOV
743
            $loader->load('validator/validator.xml');
×
744

UNCOV
745
            if ($this->isConfigEnabled($container, $config['graphql'])) {
×
UNCOV
746
                $loader->load('graphql/validator.xml');
×
747
            }
748

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

UNCOV
751
            $container->registerForAutoconfiguration(ValidationGroupsGeneratorInterface::class)
×
UNCOV
752
                ->addTag('api_platform.validation_groups_generator');
×
UNCOV
753
            $container->registerForAutoconfiguration(PropertySchemaRestrictionMetadataInterface::class)
×
UNCOV
754
                ->addTag('api_platform.metadata.property_schema_restriction');
×
755
        }
756

UNCOV
757
        if (!$config['validator']) {
×
758
            return;
×
759
        }
760

UNCOV
761
        $container->setParameter('api_platform.validator.serialize_payload_fields', $config['validator']['serialize_payload_fields']);
×
762
    }
763

764
    private function registerDataCollectorConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
765
    {
UNCOV
766
        if (!$config['enable_profiler']) {
×
767
            return;
×
768
        }
769

UNCOV
770
        $loader->load('data_collector.xml');
×
771

UNCOV
772
        if ($container->hasParameter('kernel.debug') && $container->getParameter('kernel.debug')) {
×
UNCOV
773
            $loader->load('debug.xml');
×
774
        }
775
    }
776

777
    private function registerMercureConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
778
    {
UNCOV
779
        if (!$this->isConfigEnabled($container, $config['mercure'])) {
×
780
            return;
×
781
        }
782

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

UNCOV
786
        if ($this->isConfigEnabled($container, $config['doctrine'])) {
×
UNCOV
787
            $loader->load('doctrine_orm_mercure_publisher.xml');
×
788
        }
UNCOV
789
        if ($this->isConfigEnabled($container, $config['doctrine_mongodb_odm'])) {
×
790
            $loader->load('doctrine_odm_mercure_publisher.xml');
×
791
        }
792

UNCOV
793
        if ($this->isConfigEnabled($container, $config['graphql'])) {
×
UNCOV
794
            $loader->load('graphql_mercure.xml');
×
795
        }
796
    }
797

798
    private function registerMessengerConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
799
    {
UNCOV
800
        if (!$this->isConfigEnabled($container, $config['messenger'])) {
×
801
            return;
×
802
        }
803

UNCOV
804
        $loader->load('messenger.xml');
×
805
    }
806

807
    private function registerElasticsearchConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
808
    {
UNCOV
809
        $enabled = $this->isConfigEnabled($container, $config['elasticsearch']);
×
810

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

UNCOV
813
        if (!$enabled) {
×
UNCOV
814
            return;
×
815
        }
816

817
        $clientClass = !class_exists(\Elasticsearch\Client::class)
×
818
            // ES v7
×
819
            ? \Elastic\Elasticsearch\Client::class
×
820
            // ES v8 and up
×
821
            : \Elasticsearch\Client::class;
×
822

823
        $clientDefinition = new Definition($clientClass);
×
824
        $container->setDefinition('api_platform.elasticsearch.client', $clientDefinition);
×
825
        $container->registerForAutoconfiguration(RequestBodySearchCollectionExtensionInterface::class)
×
826
            ->addTag('api_platform.elasticsearch.request_body_search_extension.collection');
×
827
        $container->setParameter('api_platform.elasticsearch.hosts', $config['elasticsearch']['hosts']);
×
828
        $loader->load('elasticsearch.xml');
×
829
    }
830

831
    private function registerSecurityConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
832
    {
833
        /** @var string[] $bundles */
UNCOV
834
        $bundles = $container->getParameter('kernel.bundles');
×
835

UNCOV
836
        if (!isset($bundles['SecurityBundle'])) {
×
837
            return;
×
838
        }
839

UNCOV
840
        $loader->load('security.xml');
×
841

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

UNCOV
844
        if (interface_exists(ValidatorInterface::class)) {
×
UNCOV
845
            $loader->load('state/security_validator.xml');
×
846
        }
847

UNCOV
848
        if ($this->isConfigEnabled($container, $config['graphql'])) {
×
UNCOV
849
            $loader->load('graphql/security.xml');
×
850
        }
851
    }
852

853
    private function registerOpenApiConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
854
    {
UNCOV
855
        $container->setParameter('api_platform.openapi.termsOfService', $config['openapi']['termsOfService']);
×
UNCOV
856
        $container->setParameter('api_platform.openapi.contact.name', $config['openapi']['contact']['name']);
×
UNCOV
857
        $container->setParameter('api_platform.openapi.contact.url', $config['openapi']['contact']['url']);
×
UNCOV
858
        $container->setParameter('api_platform.openapi.contact.email', $config['openapi']['contact']['email']);
×
UNCOV
859
        $container->setParameter('api_platform.openapi.license.name', $config['openapi']['license']['name']);
×
UNCOV
860
        $container->setParameter('api_platform.openapi.license.url', $config['openapi']['license']['url']);
×
UNCOV
861
        $container->setParameter('api_platform.openapi.license.identifier', $config['openapi']['license']['identifier']);
×
UNCOV
862
        $container->setParameter('api_platform.openapi.overrideResponses', $config['openapi']['overrideResponses']);
×
863

UNCOV
864
        $tags = [];
×
865
        foreach ($config['openapi']['tags'] as $tag) {
×
UNCOV
866
            $tags[] = new Tag($tag['name'], $tag['description'] ?? null);
×
867
        }
868

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

UNCOV
871
        $container->setParameter('api_platform.openapi.errorResourceClass', $config['openapi']['error_resource_class'] ?? null);
×
UNCOV
872
        $container->setParameter('api_platform.openapi.validationErrorResourceClass', $config['openapi']['validation_error_resource_class'] ?? null);
×
873

UNCOV
874
        $loader->load('json_schema.xml');
×
875
    }
876

877
    private function registerMakerConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
878
    {
UNCOV
879
        if (!$this->isConfigEnabled($container, $config['maker'])) {
×
UNCOV
880
            return;
×
881
        }
882

UNCOV
883
        $loader->load('maker.xml');
×
884
    }
885

886
    private function registerArgumentResolverConfiguration(XmlFileLoader $loader): void
887
    {
UNCOV
888
        $loader->load('argument_resolver.xml');
×
889
    }
890

891
    private function registerLinkSecurityConfiguration(XmlFileLoader $loader, array $config): void
892
    {
UNCOV
893
        if ($config['enable_link_security']) {
×
UNCOV
894
            $loader->load('link_security.xml');
×
895
        }
896
    }
897
}
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