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

api-platform / core / 15283185369

27 May 2025 06:43PM UTC coverage: 0.0% (-26.4%) from 26.397%
15283185369

Pull #7180

github

web-flow
Merge 9a6703d44 into c022b441b
Pull Request #7180: feat(deps): allow Elasticsearch v9

0 of 51334 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/Configuration.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\Common\Filter\OrderFilterInterface;
17
use ApiPlatform\Metadata\ApiResource;
18
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
19
use ApiPlatform\Metadata\Post;
20
use ApiPlatform\Metadata\Put;
21
use ApiPlatform\Symfony\Controller\MainController;
22
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
23
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
24
use Doctrine\ORM\EntityManagerInterface;
25
use Doctrine\ORM\OptimisticLockException;
26
use GraphQL\GraphQL;
27
use Symfony\Bundle\FullStack;
28
use Symfony\Bundle\MakerBundle\MakerBundle;
29
use Symfony\Bundle\MercureBundle\MercureBundle;
30
use Symfony\Bundle\TwigBundle\TwigBundle;
31
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
32
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
33
use Symfony\Component\Config\Definition\ConfigurationInterface;
34
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
35
use Symfony\Component\HttpFoundation\Response;
36
use Symfony\Component\Messenger\MessageBusInterface;
37
use Symfony\Component\Serializer\Exception\ExceptionInterface as SerializerExceptionInterface;
38
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
39
use Symfony\Component\Yaml\Yaml;
40

41
/**
42
 * The configuration of the bundle.
43
 *
44
 * @author Kévin Dunglas <dunglas@gmail.com>
45
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
46
 */
47
final class Configuration implements ConfigurationInterface
48
{
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getConfigTreeBuilder(): TreeBuilder
53
    {
54
        $treeBuilder = new TreeBuilder('api_platform');
×
55
        $rootNode = $treeBuilder->getRootNode();
×
56

57
        $rootNode
×
58
            ->beforeNormalization()
×
59
                ->ifTrue(static function ($v) {
×
60
                    return false === ($v['enable_swagger'] ?? null);
×
61
                })
×
62
                ->then(static function ($v) {
×
63
                    $v['swagger']['versions'] = [];
×
64

65
                    return $v;
×
66
                })
×
67
            ->end()
×
68
            ->children()
×
69
                ->scalarNode('title')
×
70
                    ->info('The title of the API.')
×
71
                    ->cannotBeEmpty()
×
72
                    ->defaultValue('')
×
73
                ->end()
×
74
                ->scalarNode('description')
×
75
                    ->info('The description of the API.')
×
76
                    ->cannotBeEmpty()
×
77
                    ->defaultValue('')
×
78
                ->end()
×
79
                ->scalarNode('version')
×
80
                    ->info('The version of the API.')
×
81
                    ->cannotBeEmpty()
×
82
                    ->defaultValue('0.0.0')
×
83
                ->end()
×
84
                ->booleanNode('show_webby')->defaultTrue()->info('If true, show Webby on the documentation page')->end()
×
85
                ->booleanNode('use_symfony_listeners')->defaultFalse()->info(sprintf('Uses Symfony event listeners instead of the %s.', MainController::class))->end()
×
86
                ->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end()
×
87
                ->scalarNode('asset_package')->defaultNull()->info('Specify an asset package name to use.')->end()
×
88
                ->scalarNode('path_segment_name_generator')->defaultValue('api_platform.metadata.path_segment_name_generator.underscore')->info('Specify a path name generator to use.')->end()
×
89
                ->scalarNode('inflector')->defaultValue('api_platform.metadata.inflector')->info('Specify an inflector to use.')->end()
×
90
                ->arrayNode('validator')
×
91
                    ->addDefaultsIfNotSet()
×
92
                    ->children()
×
93
                        ->variableNode('serialize_payload_fields')->defaultValue([])->info('Set to null to serialize all payload fields when a validation error is thrown, or set the fields you want to include explicitly.')->end()
×
94
                        ->booleanNode('query_parameter_validation')
×
95
                            ->defaultValue(true)
×
96
                            ->setDeprecated('api-platform/symfony', '4.2', 'Will be removed in API Platform 5.0.')
×
97
                        ->end()
×
98
                    ->end()
×
99
                ->end()
×
100
                ->arrayNode('eager_loading')
×
101
                    ->canBeDisabled()
×
102
                    ->addDefaultsIfNotSet()
×
103
                    ->children()
×
104
                        ->booleanNode('fetch_partial')->defaultFalse()->info('Fetch only partial data according to serialization groups. If enabled, Doctrine ORM entities will not work as expected if any of the other fields are used.')->end()
×
105
                        ->integerNode('max_joins')->defaultValue(30)->info('Max number of joined relations before EagerLoading throws a RuntimeException')->end()
×
106
                        ->booleanNode('force_eager')->defaultTrue()->info('Force join on every relation. If disabled, it will only join relations having the EAGER fetch mode.')->end()
×
107
                    ->end()
×
108
                ->end()
×
109
                ->booleanNode('handle_symfony_errors')->defaultFalse()->info('Allows to handle symfony exceptions.')->end()
×
110
                ->booleanNode('enable_swagger')->defaultTrue()->info('Enable the Swagger documentation and export.')->end()
×
111
                ->booleanNode('enable_swagger_ui')->defaultValue(class_exists(TwigBundle::class))->info('Enable Swagger UI')->end()
×
112
                ->booleanNode('enable_re_doc')->defaultValue(class_exists(TwigBundle::class))->info('Enable ReDoc')->end()
×
113
                ->booleanNode('enable_entrypoint')->defaultTrue()->info('Enable the entrypoint')->end()
×
114
                ->booleanNode('enable_docs')->defaultTrue()->info('Enable the docs')->end()
×
115
                ->booleanNode('enable_profiler')->defaultTrue()->info('Enable the data collector and the WebProfilerBundle integration.')->end()
×
116
                ->booleanNode('enable_link_security')->defaultFalse()->info('Enable security for Links (sub resources)')->end()
×
117
                ->arrayNode('collection')
×
118
                    ->addDefaultsIfNotSet()
×
119
                    ->children()
×
120
                        ->scalarNode('exists_parameter_name')->defaultValue('exists')->cannotBeEmpty()->info('The name of the query parameter to filter on nullable field values.')->end()
×
121
                        ->scalarNode('order')->defaultValue('ASC')->info('The default order of results.')->end() // Default ORDER is required for postgresql and mysql >= 5.7 when using LIMIT/OFFSET request
×
122
                        ->scalarNode('order_parameter_name')->defaultValue('order')->cannotBeEmpty()->info('The name of the query parameter to order results.')->end()
×
123
                        ->enumNode('order_nulls_comparison')->defaultNull()->values(interface_exists(OrderFilterInterface::class) ? array_merge(array_keys(OrderFilterInterface::NULLS_DIRECTION_MAP), [null]) : [null])->info('The nulls comparison strategy.')->end()
×
124
                        ->arrayNode('pagination')
×
125
                            ->canBeDisabled()
×
126
                            ->addDefaultsIfNotSet()
×
127
                            ->children()
×
128
                                ->scalarNode('page_parameter_name')->defaultValue('page')->cannotBeEmpty()->info('The default name of the parameter handling the page number.')->end()
×
129
                                ->scalarNode('enabled_parameter_name')->defaultValue('pagination')->cannotBeEmpty()->info('The name of the query parameter to enable or disable pagination.')->end()
×
130
                                ->scalarNode('items_per_page_parameter_name')->defaultValue('itemsPerPage')->cannotBeEmpty()->info('The name of the query parameter to set the number of items per page.')->end()
×
131
                                ->scalarNode('partial_parameter_name')->defaultValue('partial')->cannotBeEmpty()->info('The name of the query parameter to enable or disable partial pagination.')->end()
×
132
                            ->end()
×
133
                        ->end()
×
134
                    ->end()
×
135
                ->end()
×
136
                ->arrayNode('mapping')
×
137
                    ->addDefaultsIfNotSet()
×
138
                    ->children()
×
139
                        ->arrayNode('paths')
×
140
                            ->prototype('scalar')->end()
×
141
                        ->end()
×
142
                    ->end()
×
143
                ->end()
×
144
                ->arrayNode('resource_class_directories')
×
145
                    ->prototype('scalar')->end()
×
146
                    ->setDeprecated('api-platform/symfony', '4.1', 'The "resource_class_directories" configuration is deprecated, classes using #[ApiResource] attribute are autoconfigured by the dependency injection container.')
×
147
                ->end()
×
148
                ->arrayNode('serializer')
×
149
                    ->addDefaultsIfNotSet()
×
150
                    ->children()
×
151
                        ->booleanNode('hydra_prefix')->defaultFalse()->info('Use the "hydra:" prefix.')->end()
×
152
                    ->end()
×
153
                ->end()
×
154
            ->end();
×
155

156
        $this->addDoctrineOrmSection($rootNode);
×
157
        $this->addDoctrineMongoDbOdmSection($rootNode);
×
158
        $this->addOAuthSection($rootNode);
×
159
        $this->addGraphQlSection($rootNode);
×
160
        $this->addSwaggerSection($rootNode);
×
161
        $this->addHttpCacheSection($rootNode);
×
162
        $this->addMercureSection($rootNode);
×
163
        $this->addMessengerSection($rootNode);
×
164
        $this->addElasticsearchSection($rootNode);
×
165
        $this->addOpenApiSection($rootNode);
×
166
        $this->addMakerSection($rootNode);
×
167

168
        $this->addExceptionToStatusSection($rootNode);
×
169

170
        $this->addFormatSection($rootNode, 'formats', [
×
171
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
172
        ]);
×
173
        $this->addFormatSection($rootNode, 'patch_formats', [
×
174
            'json' => ['mime_types' => ['application/merge-patch+json']],
×
175
        ]);
×
176

177
        $defaultDocFormats = [
×
178
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
179
            'jsonopenapi' => ['mime_types' => ['application/vnd.openapi+json']],
×
180
            'html' => ['mime_types' => ['text/html']],
×
181
        ];
×
182

183
        if (class_exists(Yaml::class)) {
×
184
            $defaultDocFormats['yamlopenapi'] = ['mime_types' => ['application/vnd.openapi+yaml']];
×
185
        }
186

187
        $this->addFormatSection($rootNode, 'docs_formats', $defaultDocFormats);
×
188

189
        $this->addFormatSection($rootNode, 'error_formats', [
×
190
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
191
            'jsonproblem' => ['mime_types' => ['application/problem+json']],
×
192
            'json' => ['mime_types' => ['application/problem+json', 'application/json']],
×
193
        ]);
×
194
        $rootNode
×
195
            ->children()
×
196
                ->arrayNode('jsonschema_formats')
×
197
                    ->scalarPrototype()->end()
×
198
                    ->defaultValue([])
×
199
                    ->info('The JSON formats to compute the JSON Schemas for.')
×
200
                ->end()
×
201
            ->end();
×
202

203
        $this->addDefaultsSection($rootNode);
×
204

205
        return $treeBuilder;
×
206
    }
207

208
    private function addDoctrineOrmSection(ArrayNodeDefinition $rootNode): void
209
    {
210
        $rootNode
×
211
            ->children()
×
212
                ->arrayNode('doctrine')
×
213
                    ->{class_exists(DoctrineBundle::class) && interface_exists(EntityManagerInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
214
                ->end()
×
215
            ->end();
×
216
    }
217

218
    private function addDoctrineMongoDbOdmSection(ArrayNodeDefinition $rootNode): void
219
    {
220
        $rootNode
×
221
            ->children()
×
222
                ->arrayNode('doctrine_mongodb_odm')
×
223
                    ->{class_exists(DoctrineMongoDBBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
224
                ->end()
×
225
            ->end();
×
226
    }
227

228
    private function addOAuthSection(ArrayNodeDefinition $rootNode): void
229
    {
230
        $rootNode
×
231
            ->children()
×
232
                ->arrayNode('oauth')
×
233
                    ->canBeEnabled()
×
234
                    ->addDefaultsIfNotSet()
×
235
                    ->children()
×
236
                        ->scalarNode('clientId')->defaultValue('')->info('The oauth client id.')->end()
×
237
                        ->scalarNode('clientSecret')
×
238
                            ->defaultValue('')
×
239
                            ->info('The OAuth client secret. Never use this parameter in your production environment. It exposes crucial security information. This feature is intended for dev/test environments only. Enable "oauth.pkce" instead')
×
240
                        ->end()
×
241
                        ->booleanNode('pkce')->defaultFalse()->info('Enable the oauth PKCE.')->end()
×
242
                        ->scalarNode('type')->defaultValue('oauth2')->info('The oauth type.')->end()
×
243
                        ->scalarNode('flow')->defaultValue('application')->info('The oauth flow grant type.')->end()
×
244
                        ->scalarNode('tokenUrl')->defaultValue('')->info('The oauth token url.')->end()
×
245
                        ->scalarNode('authorizationUrl')->defaultValue('')->info('The oauth authentication url.')->end()
×
246
                        ->scalarNode('refreshUrl')->defaultValue('')->info('The oauth refresh url.')->end()
×
247
                        ->arrayNode('scopes')
×
248
                            ->prototype('scalar')->end()
×
249
                        ->end()
×
250
                    ->end()
×
251
                ->end()
×
252
            ->end();
×
253
    }
254

255
    private function addGraphQlSection(ArrayNodeDefinition $rootNode): void
256
    {
257
        $rootNode
×
258
            ->children()
×
259
                ->arrayNode('graphql')
×
260
                    ->{class_exists(GraphQL::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
261
                    ->addDefaultsIfNotSet()
×
262
                    ->children()
×
263
                        ->scalarNode('default_ide')->defaultValue('graphiql')->end()
×
264
                        ->arrayNode('graphiql')
×
265
                            ->{class_exists(GraphQL::class) && class_exists(TwigBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
266
                        ->end()
×
267
                        ->arrayNode('graphql_playground')
×
268
                            ->{class_exists(GraphQL::class) && class_exists(TwigBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
269
                        ->end()
×
270
                        ->arrayNode('introspection')
×
271
                            ->canBeDisabled()
×
272
                        ->end()
×
273
                        ->integerNode('max_query_depth')->defaultValue(20)
×
274
                        ->end()
×
275
                        ->integerNode('max_query_complexity')->defaultValue(500)
×
276
                        ->end()
×
277
                        ->scalarNode('nesting_separator')->defaultValue('_')->info('The separator to use to filter nested fields.')->end()
×
278
                        ->arrayNode('collection')
×
279
                            ->addDefaultsIfNotSet()
×
280
                            ->children()
×
281
                                ->arrayNode('pagination')
×
282
                                    ->canBeDisabled()
×
283
                                ->end()
×
284
                            ->end()
×
285
                        ->end()
×
286
                    ->end()
×
287
                ->end()
×
288
            ->end();
×
289
    }
290

291
    private function addSwaggerSection(ArrayNodeDefinition $rootNode): void
292
    {
293
        $supportedVersions = [3];
×
294

295
        $rootNode
×
296
            ->children()
×
297
                ->arrayNode('swagger')
×
298
                    ->addDefaultsIfNotSet()
×
299
                    ->children()
×
300
                        ->booleanNode('persist_authorization')->defaultValue(false)->info('Persist the SwaggerUI Authorization in the localStorage.')->end()
×
301
                        ->arrayNode('versions')
×
302
                            ->info('The active versions of OpenAPI to be exported or used in Swagger UI. The first value is the default.')
×
303
                            ->defaultValue($supportedVersions)
×
304
                            ->beforeNormalization()
×
305
                                ->always(static function ($v): array {
×
306
                                    if (!\is_array($v)) {
×
307
                                        $v = [$v];
×
308
                                    }
309

310
                                    foreach ($v as &$version) {
×
311
                                        $version = (int) $version;
×
312
                                    }
313

314
                                    return $v;
×
315
                                })
×
316
                            ->end()
×
317
                            ->validate()
×
318
                                ->ifTrue(static fn ($v): bool => $v !== array_intersect($v, $supportedVersions))
×
319
                                ->thenInvalid(sprintf('Only the versions %s are supported. Got %s.', implode(' and ', $supportedVersions), '%s'))
×
320
                            ->end()
×
321
                            ->prototype('scalar')->end()
×
322
                        ->end()
×
323
                        ->arrayNode('api_keys')
×
324
                            ->useAttributeAsKey('key')
×
325
                            ->validate()
×
326
                                ->ifTrue(static fn ($v): bool => (bool) array_filter(array_keys($v), fn ($item) => !preg_match('/^[a-zA-Z0-9._-]+$/', $item)))
×
327
                                ->thenInvalid('The api keys "key" is not valid according to the pattern enforced by OpenAPI 3.1 ^[a-zA-Z0-9._-]+$.')
×
328
                            ->end()
×
329
                            ->prototype('array')
×
330
                                ->children()
×
331
                                    ->scalarNode('name')
×
332
                                        ->info('The name of the header or query parameter containing the api key.')
×
333
                                    ->end()
×
334
                                    ->enumNode('type')
×
335
                                        ->info('Whether the api key should be a query parameter or a header.')
×
336
                                        ->values(['query', 'header'])
×
337
                                    ->end()
×
338
                                ->end()
×
339
                            ->end()
×
340
                        ->end()
×
341
                        ->arrayNode('http_auth')
×
342
                            ->info('Creates http security schemes for OpenAPI.')
×
343
                            ->useAttributeAsKey('key')
×
344
                            ->validate()
×
345
                                ->ifTrue(static fn ($v): bool => (bool) array_filter(array_keys($v), fn ($item) => !preg_match('/^[a-zA-Z0-9._-]+$/', $item)))
×
346
                                ->thenInvalid('The api keys "key" is not valid according to the pattern enforced by OpenAPI 3.1 ^[a-zA-Z0-9._-]+$.')
×
347
                            ->end()
×
348
                            ->prototype('array')
×
349
                                ->children()
×
350
                                    ->scalarNode('scheme')
×
351
                                        ->info('The OpenAPI HTTP auth scheme, for example "bearer"')
×
352
                                    ->end()
×
353
                                    ->scalarNode('bearerFormat')
×
354
                                        ->info('The OpenAPI HTTP bearer format')
×
355
                                    ->end()
×
356
                                ->end()
×
357
                            ->end()
×
358
                        ->end()
×
359
                        ->variableNode('swagger_ui_extra_configuration')
×
360
                            ->defaultValue([])
×
361
                            ->validate()
×
362
                                ->ifTrue(static fn ($v): bool => false === \is_array($v))
×
363
                                ->thenInvalid('The swagger_ui_extra_configuration parameter must be an array.')
×
364
                            ->end()
×
365
                            ->info('To pass extra configuration to Swagger UI, like docExpansion or filter.')
×
366
                        ->end()
×
367
                    ->end()
×
368
                ->end()
×
369
            ->end();
×
370
    }
371

372
    private function addHttpCacheSection(ArrayNodeDefinition $rootNode): void
373
    {
374
        $rootNode
×
375
            ->children()
×
376
                ->arrayNode('http_cache')
×
377
                    ->addDefaultsIfNotSet()
×
378
                    ->children()
×
379
                        ->booleanNode('public')->defaultNull()->info('To make all responses public by default.')->end()
×
380
                        ->arrayNode('invalidation')
×
381
                            ->info('Enable the tags-based cache invalidation system.')
×
382
                            ->canBeEnabled()
×
383
                            ->children()
×
384
                                ->arrayNode('varnish_urls')
×
385
                                    ->setDeprecated('api-platform/core', '3.0', 'The "varnish_urls" configuration is deprecated, use "urls" or "scoped_clients".')
×
386
                                    ->defaultValue([])
×
387
                                    ->prototype('scalar')->end()
×
388
                                    ->info('URLs of the Varnish servers to purge using cache tags when a resource is updated.')
×
389
                                ->end()
×
390
                                ->arrayNode('urls')
×
391
                                    ->defaultValue([])
×
392
                                    ->prototype('scalar')->end()
×
393
                                    ->info('URLs of the Varnish servers to purge using cache tags when a resource is updated.')
×
394
                                ->end()
×
395
                                ->arrayNode('scoped_clients')
×
396
                                    ->defaultValue([])
×
397
                                    ->prototype('scalar')->end()
×
398
                                    ->info('Service names of scoped client to use by the cache purger.')
×
399
                                ->end()
×
400
                                ->integerNode('max_header_length')
×
401
                                    ->defaultValue(7500)
×
402
                                    ->info('Max header length supported by the cache server.')
×
403
                                ->end()
×
404
                                ->variableNode('request_options')
×
405
                                    ->defaultValue([])
×
406
                                    ->validate()
×
407
                                        ->ifTrue(static fn ($v): bool => false === \is_array($v))
×
408
                                        ->thenInvalid('The request_options parameter must be an array.')
×
409
                                    ->end()
×
410
                                    ->info('To pass options to the client charged with the request.')
×
411
                                ->end()
×
412
                                ->scalarNode('purger')
×
413
                                    ->defaultValue('api_platform.http_cache.purger.varnish')
×
414
                                    ->info('Specify a purger to use (available values: "api_platform.http_cache.purger.varnish.ban", "api_platform.http_cache.purger.varnish.xkey", "api_platform.http_cache.purger.souin").')
×
415
                                ->end()
×
416
                                ->arrayNode('xkey')
×
417
                                    ->setDeprecated('api-platform/core', '3.0', 'The "xkey" configuration is deprecated, use your own purger to customize surrogate keys or the appropriate paramters.')
×
418
                                    ->addDefaultsIfNotSet()
×
419
                                    ->children()
×
420
                                        ->scalarNode('glue')
×
421
                                        ->defaultValue(' ')
×
422
                                        ->info('xkey glue between keys')
×
423
                                        ->end()
×
424
                                    ->end()
×
425
                                ->end()
×
426
                            ->end()
×
427
                        ->end()
×
428
                    ->end()
×
429
                ->end()
×
430
            ->end();
×
431
    }
432

433
    private function addMercureSection(ArrayNodeDefinition $rootNode): void
434
    {
435
        $rootNode
×
436
            ->children()
×
437
                ->arrayNode('mercure')
×
438
                    ->{class_exists(MercureBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
439
                    ->children()
×
440
                        ->scalarNode('hub_url')
×
441
                            ->defaultNull()
×
442
                            ->info('The URL sent in the Link HTTP header. If not set, will default to the URL for MercureBundle\'s default hub.')
×
443
                        ->end()
×
444
                        ->booleanNode('include_type')
×
445
                            ->defaultFalse()
×
446
                            ->info('Always include @type in updates (including delete ones).')
×
447
                        ->end()
×
448
                    ->end()
×
449
                ->end()
×
450
            ->end();
×
451
    }
452

453
    private function addMessengerSection(ArrayNodeDefinition $rootNode): void
454
    {
455
        $rootNode
×
456
            ->children()
×
457
                ->arrayNode('messenger')
×
458
                    ->{!class_exists(FullStack::class) && interface_exists(MessageBusInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
459
                ->end()
×
460
            ->end();
×
461
    }
462

463
    private function addElasticsearchSection(ArrayNodeDefinition $rootNode): void
464
    {
465
        $rootNode
×
466
            ->children()
×
467
                ->arrayNode('elasticsearch')
×
468
                    ->canBeEnabled()
×
469
                    ->addDefaultsIfNotSet()
×
470
                    ->children()
×
471
                        ->booleanNode('enabled')
×
472
                            ->defaultFalse()
×
473
                            ->validate()
×
474
                                ->ifTrue()
×
475
                                ->then(static function (bool $v): bool {
×
476
                                    if (
477
                                        // ES v7
478
                                        !class_exists(\Elasticsearch\Client::class)
×
479
                                        // ES v8 and up
480
                                        && !class_exists(\Elastic\Elasticsearch\Client::class)
×
481
                                    ) {
482
                                        throw new InvalidConfigurationException('The elasticsearch/elasticsearch package is required for Elasticsearch support.');
×
483
                                    }
484

485
                                    return $v;
×
486
                                })
×
487
                            ->end()
×
488
                        ->end()
×
489
                        ->arrayNode('hosts')
×
490
                            ->beforeNormalization()->castToArray()->end()
×
491
                            ->defaultValue([])
×
492
                            ->prototype('scalar')->end()
×
493
                        ->end()
×
494
                    ->end()
×
495
                ->end()
×
496
            ->end();
×
497
    }
498

499
    private function addOpenApiSection(ArrayNodeDefinition $rootNode): void
500
    {
501
        $rootNode
×
502
            ->children()
×
503
                ->arrayNode('openapi')
×
504
                    ->addDefaultsIfNotSet()
×
505
                        ->children()
×
506
                        ->arrayNode('contact')
×
507
                        ->addDefaultsIfNotSet()
×
508
                            ->children()
×
509
                                ->scalarNode('name')->defaultNull()->info('The identifying name of the contact person/organization.')->end()
×
510
                                ->scalarNode('url')->defaultNull()->info('The URL pointing to the contact information. MUST be in the format of a URL.')->end()
×
511
                                ->scalarNode('email')->defaultNull()->info('The email address of the contact person/organization. MUST be in the format of an email address.')->end()
×
512
                            ->end()
×
513
                        ->end()
×
514
                        ->scalarNode('termsOfService')->defaultNull()->info('A URL to the Terms of Service for the API. MUST be in the format of a URL.')->end()
×
515
                        ->arrayNode('tags')
×
516
                            ->info('Global OpenApi tags overriding the default computed tags if specified.')
×
517
                            ->prototype('array')
×
518
                                ->children()
×
519
                                    ->scalarNode('name')->isRequired()->end()
×
520
                                    ->scalarNode('description')->defaultNull()->end()
×
521
                                ->end()
×
522
                            ->end()
×
523
                        ->end()
×
524
                        ->arrayNode('license')
×
525
                        ->addDefaultsIfNotSet()
×
526
                            ->children()
×
527
                                ->scalarNode('name')->defaultNull()->info('The license name used for the API.')->end()
×
528
                                ->scalarNode('url')->defaultNull()->info('URL to the license used for the API. MUST be in the format of a URL.')->end()
×
529
                                ->scalarNode('identifier')->defaultNull()->info('An SPDX license expression for the API. The identifier field is mutually exclusive of the url field.')->end()
×
530
                            ->end()
×
531
                        ->end()
×
532
                        ->variableNode('swagger_ui_extra_configuration')
×
533
                            ->defaultValue([])
×
534
                            ->validate()
×
535
                                ->ifTrue(static fn ($v): bool => false === \is_array($v))
×
536
                                ->thenInvalid('The swagger_ui_extra_configuration parameter must be an array.')
×
537
                            ->end()
×
538
                            ->info('To pass extra configuration to Swagger UI, like docExpansion or filter.')
×
539
                        ->end()
×
540
                        ->booleanNode('overrideResponses')->defaultTrue()->info('Whether API Platform adds automatic responses to the OpenAPI documentation.')->end()
×
541
                        ->scalarNode('error_resource_class')->defaultNull()->info('The class used to represent errors in the OpenAPI documentation.')->end()
×
542
                        ->scalarNode('validation_error_resource_class')->defaultNull()->info('The class used to represent validation errors in the OpenAPI documentation.')->end()
×
543
                    ->end()
×
544
                ->end()
×
545
            ->end();
×
546
    }
547

548
    /**
549
     * @throws InvalidConfigurationException
550
     */
551
    private function addExceptionToStatusSection(ArrayNodeDefinition $rootNode): void
552
    {
553
        $rootNode
×
554
            ->children()
×
555
                ->arrayNode('exception_to_status')
×
556
                    ->defaultValue([
×
557
                        SerializerExceptionInterface::class => Response::HTTP_BAD_REQUEST,
×
558
                        InvalidArgumentException::class => Response::HTTP_BAD_REQUEST,
×
559
                        OptimisticLockException::class => Response::HTTP_CONFLICT,
×
560
                    ])
×
561
                    ->info('The list of exceptions mapped to their HTTP status code.')
×
562
                    ->normalizeKeys(false)
×
563
                    ->useAttributeAsKey('exception_class')
×
564
                    ->prototype('integer')->end()
×
565
                    ->validate()
×
566
                        ->ifArray()
×
567
                        ->then(static function (array $exceptionToStatus): array {
×
568
                            foreach ($exceptionToStatus as $httpStatusCode) {
×
569
                                if ($httpStatusCode < 100 || $httpStatusCode >= 600) {
×
570
                                    throw new InvalidConfigurationException(sprintf('The HTTP status code "%s" is not valid.', $httpStatusCode));
×
571
                                }
572
                            }
573

574
                            return $exceptionToStatus;
×
575
                        })
×
576
                    ->end()
×
577
                ->end()
×
578
            ->end();
×
579
    }
580

581
    private function addFormatSection(ArrayNodeDefinition $rootNode, string $key, array $defaultValue): void
582
    {
583
        $rootNode
×
584
            ->children()
×
585
                ->arrayNode($key)
×
586
                    ->defaultValue($defaultValue)
×
587
                    ->info('The list of enabled formats. The first one will be the default.')
×
588
                    ->normalizeKeys(false)
×
589
                    ->useAttributeAsKey('format')
×
590
                    ->beforeNormalization()
×
591
                        ->ifArray()
×
592
                        ->then(static function ($v) {
×
593
                            foreach ($v as $format => $value) {
×
594
                                if (isset($value['mime_types'])) {
×
595
                                    continue;
×
596
                                }
597

598
                                $v[$format] = ['mime_types' => $value];
×
599
                            }
600

601
                            return $v;
×
602
                        })
×
603
                    ->end()
×
604
                    ->prototype('array')
×
605
                        ->children()
×
606
                            ->arrayNode('mime_types')->prototype('scalar')->end()->end()
×
607
                        ->end()
×
608
                    ->end()
×
609
                ->end()
×
610
            ->end();
×
611
    }
612

613
    private function addDefaultsSection(ArrayNodeDefinition $rootNode): void
614
    {
615
        $nameConverter = new CamelCaseToSnakeCaseNameConverter();
×
616
        $defaultsNode = $rootNode->children()->arrayNode('defaults');
×
617

618
        $defaultsNode
×
619
            ->ignoreExtraKeys(false)
×
620
            ->beforeNormalization()
×
621
            ->always(static function (array $defaults) use ($nameConverter): array {
×
622
                $normalizedDefaults = [];
×
623
                foreach ($defaults as $option => $value) {
×
624
                    $option = $nameConverter->normalize($option);
×
625
                    $normalizedDefaults[$option] = $value;
×
626
                }
627

628
                return $normalizedDefaults;
×
629
            });
×
630

631
        $this->defineDefault($defaultsNode, new \ReflectionClass(ApiResource::class), $nameConverter);
×
632
        $this->defineDefault($defaultsNode, new \ReflectionClass(Put::class), $nameConverter);
×
633
        $this->defineDefault($defaultsNode, new \ReflectionClass(Post::class), $nameConverter);
×
634
    }
635

636
    private function addMakerSection(ArrayNodeDefinition $rootNode): void
637
    {
638
        $rootNode
×
639
            ->children()
×
640
                ->arrayNode('maker')
×
641
                    ->{class_exists(MakerBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
642
                ->end()
×
643
            ->end();
×
644
    }
645

646
    private function defineDefault(ArrayNodeDefinition $defaultsNode, \ReflectionClass $reflectionClass, CamelCaseToSnakeCaseNameConverter $nameConverter): void
647
    {
648
        foreach ($reflectionClass->getConstructor()->getParameters() as $parameter) {
×
649
            $defaultsNode->children()->variableNode($nameConverter->normalize($parameter->getName()));
×
650
        }
651
    }
652
}
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