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

api-platform / core / 20969151198

13 Jan 2026 07:07PM UTC coverage: 0.0% (-29.1%) from 29.095%
20969151198

Pull #7669

github

web-flow
Merge 872bbc755 into c8493bbe7
Pull Request #7669: ci - fix testMapPutAllowCreate

0 of 57775 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\FrameworkBundle\Controller\ControllerHelper;
28
use Symfony\Bundle\FullStack;
29
use Symfony\Bundle\MakerBundle\MakerBundle;
30
use Symfony\Bundle\MercureBundle\MercureBundle;
31
use Symfony\Bundle\TwigBundle\TwigBundle;
32
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
33
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
34
use Symfony\Component\Config\Definition\ConfigurationInterface;
35
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
36
use Symfony\Component\HttpFoundation\Response;
37
use Symfony\Component\JsonStreamer\JsonStreamWriter;
38
use Symfony\Component\Messenger\MessageBusInterface;
39
use Symfony\Component\Serializer\Exception\ExceptionInterface as SerializerExceptionInterface;
40
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
41
use Symfony\Component\Yaml\Yaml;
42

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

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

67
                    return $v;
×
68
                })
×
69
            ->end()
×
70
            ->children()
×
71
                ->scalarNode('title')
×
72
                    ->info('The title of the API.')
×
73
                    ->cannotBeEmpty()
×
74
                    ->defaultValue('')
×
75
                ->end()
×
76
                ->scalarNode('description')
×
77
                    ->info('The description of the API.')
×
78
                    ->cannotBeEmpty()
×
79
                    ->defaultValue('')
×
80
                ->end()
×
81
                ->scalarNode('version')
×
82
                    ->info('The version of the API.')
×
83
                    ->cannotBeEmpty()
×
84
                    ->defaultValue('0.0.0')
×
85
                ->end()
×
86
                ->booleanNode('show_webby')->defaultTrue()->info('If true, show Webby on the documentation page')->end()
×
87
                ->booleanNode('use_symfony_listeners')->defaultFalse()->info(sprintf('Uses Symfony event listeners instead of the %s.', MainController::class))->end()
×
88
                ->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end()
×
89
                ->scalarNode('asset_package')->defaultNull()->info('Specify an asset package name to use.')->end()
×
90
                ->scalarNode('path_segment_name_generator')->defaultValue('api_platform.metadata.path_segment_name_generator.underscore')->info('Specify a path name generator to use.')->end()
×
91
                ->scalarNode('inflector')->defaultValue('api_platform.metadata.inflector')->info('Specify an inflector to use.')->end()
×
92
                ->arrayNode('validator')
×
93
                    ->addDefaultsIfNotSet()
×
94
                    ->children()
×
95
                        ->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()
×
96
                        ->booleanNode('query_parameter_validation')
×
97
                            ->defaultValue(true)
×
98
                            ->setDeprecated('api-platform/symfony', '4.2', 'Will be removed in API Platform 5.0.')
×
99
                        ->end()
×
100
                    ->end()
×
101
                ->end()
×
102
                ->arrayNode('eager_loading')
×
103
                    ->canBeDisabled()
×
104
                    ->addDefaultsIfNotSet()
×
105
                    ->children()
×
106
                        ->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()
×
107
                        ->integerNode('max_joins')->defaultValue(30)->info('Max number of joined relations before EagerLoading throws a RuntimeException')->end()
×
108
                        ->booleanNode('force_eager')->defaultTrue()->info('Force join on every relation. If disabled, it will only join relations having the EAGER fetch mode.')->end()
×
109
                    ->end()
×
110
                ->end()
×
111
                ->booleanNode('handle_symfony_errors')->defaultFalse()->info('Allows to handle symfony exceptions.')->end()
×
112
                ->booleanNode('enable_swagger')->defaultTrue()->info('Enable the Swagger documentation and export.')->end()
×
113
                ->booleanNode('enable_json_streamer')->defaultValue(class_exists(ControllerHelper::class) && class_exists(JsonStreamWriter::class))->info('Enable json streamer.')->end()
×
114
                ->booleanNode('enable_swagger_ui')->defaultValue(class_exists(TwigBundle::class))->info('Enable Swagger UI')->end()
×
115
                ->booleanNode('enable_re_doc')->defaultValue(class_exists(TwigBundle::class))->info('Enable ReDoc')->end()
×
116
                ->booleanNode('enable_entrypoint')->defaultTrue()->info('Enable the entrypoint')->end()
×
117
                ->booleanNode('enable_docs')->defaultTrue()->info('Enable the docs')->end()
×
118
                ->booleanNode('enable_profiler')->defaultTrue()->info('Enable the data collector and the WebProfilerBundle integration.')->end()
×
119
                ->booleanNode('enable_phpdoc_parser')->defaultTrue()->info('Enable resource metadata collector using PHPStan PhpDocParser.')->end()
×
120
                ->booleanNode('enable_link_security')
×
121
                    ->defaultTrue()
×
122
                    ->info('Enable security for Links (sub resources).')
×
123
                    ->setDeprecated('api-platform/symfony', '4.2', 'This option is always enabled and will be removed in API Platform 5.0.')
×
124
                ->end()
×
125
                ->arrayNode('collection')
×
126
                    ->addDefaultsIfNotSet()
×
127
                    ->children()
×
128
                        ->scalarNode('exists_parameter_name')->defaultValue('exists')->cannotBeEmpty()->info('The name of the query parameter to filter on nullable field values.')->end()
×
129
                        ->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
×
130
                        ->scalarNode('order_parameter_name')->defaultValue('order')->cannotBeEmpty()->info('The name of the query parameter to order results.')->end()
×
131
                        ->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()
×
132
                        ->arrayNode('pagination')
×
133
                            ->canBeDisabled()
×
134
                            ->addDefaultsIfNotSet()
×
135
                            ->children()
×
136
                                ->scalarNode('page_parameter_name')->defaultValue('page')->cannotBeEmpty()->info('The default name of the parameter handling the page number.')->end()
×
137
                                ->scalarNode('enabled_parameter_name')->defaultValue('pagination')->cannotBeEmpty()->info('The name of the query parameter to enable or disable pagination.')->end()
×
138
                                ->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()
×
139
                                ->scalarNode('partial_parameter_name')->defaultValue('partial')->cannotBeEmpty()->info('The name of the query parameter to enable or disable partial pagination.')->end()
×
140
                            ->end()
×
141
                        ->end()
×
142
                    ->end()
×
143
                ->end()
×
144
                ->arrayNode('mapping')
×
145
                    ->addDefaultsIfNotSet()
×
146
                    ->children()
×
147
                        ->arrayNode('imports')
×
148
                            ->prototype('scalar')->end()
×
149
                        ->end()
×
150
                        ->arrayNode('paths')
×
151
                            ->prototype('scalar')->end()
×
152
                        ->end()
×
153
                    ->end()
×
154
                ->end()
×
155
                ->arrayNode('resource_class_directories')
×
156
                    ->prototype('scalar')->end()
×
157
                    ->setDeprecated('api-platform/symfony', '4.1', 'The "resource_class_directories" configuration is deprecated, classes using #[ApiResource] attribute are autoconfigured by the dependency injection container.')
×
158
                ->end()
×
159
                ->arrayNode('serializer')
×
160
                    ->addDefaultsIfNotSet()
×
161
                    ->children()
×
162
                        ->booleanNode('hydra_prefix')->defaultFalse()->info('Use the "hydra:" prefix.')->end()
×
163
                    ->end()
×
164
                ->end()
×
165
            ->end();
×
166

167
        $this->addDoctrineOrmSection($rootNode);
×
168
        $this->addDoctrineMongoDbOdmSection($rootNode);
×
169
        $this->addOAuthSection($rootNode);
×
170
        $this->addGraphQlSection($rootNode);
×
171
        $this->addSwaggerSection($rootNode);
×
172
        $this->addHttpCacheSection($rootNode);
×
173
        $this->addMercureSection($rootNode);
×
174
        $this->addMessengerSection($rootNode);
×
175
        $this->addElasticsearchSection($rootNode);
×
176
        $this->addOpenApiSection($rootNode);
×
177
        $this->addMakerSection($rootNode);
×
178

179
        $this->addExceptionToStatusSection($rootNode);
×
180

181
        $this->addFormatSection($rootNode, 'formats', [
×
182
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
183
        ]);
×
184
        $this->addFormatSection($rootNode, 'patch_formats', [
×
185
            'json' => ['mime_types' => ['application/merge-patch+json']],
×
186
        ]);
×
187

188
        $defaultDocFormats = [
×
189
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
190
            'jsonopenapi' => ['mime_types' => ['application/vnd.openapi+json']],
×
191
            'html' => ['mime_types' => ['text/html']],
×
192
        ];
×
193

194
        if (class_exists(Yaml::class)) {
×
195
            $defaultDocFormats['yamlopenapi'] = ['mime_types' => ['application/vnd.openapi+yaml']];
×
196
        }
197

198
        $this->addFormatSection($rootNode, 'docs_formats', $defaultDocFormats);
×
199

200
        $this->addFormatSection($rootNode, 'error_formats', [
×
201
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
202
            'jsonproblem' => ['mime_types' => ['application/problem+json']],
×
203
            'json' => ['mime_types' => ['application/problem+json', 'application/json']],
×
204
        ]);
×
205
        $rootNode
×
206
            ->children()
×
207
                ->arrayNode('jsonschema_formats')
×
208
                    ->scalarPrototype()->end()
×
209
                    ->defaultValue([])
×
210
                    ->info('The JSON formats to compute the JSON Schemas for.')
×
211
                ->end()
×
212
            ->end();
×
213

214
        $this->addDefaultsSection($rootNode);
×
215

216
        return $treeBuilder;
×
217
    }
218

219
    private function addDoctrineOrmSection(ArrayNodeDefinition $rootNode): void
220
    {
221
        $rootNode
×
222
            ->children()
×
223
                ->arrayNode('doctrine')
×
224
                    ->{class_exists(DoctrineBundle::class) && interface_exists(EntityManagerInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
225
                ->end()
×
226
            ->end();
×
227
    }
228

229
    private function addDoctrineMongoDbOdmSection(ArrayNodeDefinition $rootNode): void
230
    {
231
        $rootNode
×
232
            ->children()
×
233
                ->arrayNode('doctrine_mongodb_odm')
×
234
                    ->{class_exists(DoctrineMongoDBBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
235
                ->end()
×
236
            ->end();
×
237
    }
238

239
    private function addOAuthSection(ArrayNodeDefinition $rootNode): void
240
    {
241
        $rootNode
×
242
            ->children()
×
243
                ->arrayNode('oauth')
×
244
                    ->canBeEnabled()
×
245
                    ->addDefaultsIfNotSet()
×
246
                    ->children()
×
247
                        ->scalarNode('clientId')->defaultValue('')->info('The oauth client id.')->end()
×
248
                        ->scalarNode('clientSecret')
×
249
                            ->defaultValue('')
×
250
                            ->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')
×
251
                        ->end()
×
252
                        ->booleanNode('pkce')->defaultFalse()->info('Enable the oauth PKCE.')->end()
×
253
                        ->scalarNode('type')->defaultValue('oauth2')->info('The oauth type.')->end()
×
254
                        ->scalarNode('flow')->defaultValue('application')->info('The oauth flow grant type.')->end()
×
255
                        ->scalarNode('tokenUrl')->defaultValue('')->info('The oauth token url.')->end()
×
256
                        ->scalarNode('authorizationUrl')->defaultValue('')->info('The oauth authentication url.')->end()
×
257
                        ->scalarNode('refreshUrl')->defaultValue('')->info('The oauth refresh url.')->end()
×
258
                        ->arrayNode('scopes')
×
259
                            ->prototype('scalar')->end()
×
260
                        ->end()
×
261
                    ->end()
×
262
                ->end()
×
263
            ->end();
×
264
    }
265

266
    private function addGraphQlSection(ArrayNodeDefinition $rootNode): void
267
    {
268
        $rootNode
×
269
            ->children()
×
270
                ->arrayNode('graphql')
×
271
                    ->{class_exists(GraphQL::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
272
                    ->addDefaultsIfNotSet()
×
273
                    ->children()
×
274
                        ->scalarNode('default_ide')->defaultValue('graphiql')->end()
×
275
                        ->arrayNode('graphiql')
×
276
                            ->{class_exists(GraphQL::class) && class_exists(TwigBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
277
                        ->end()
×
278
                        ->arrayNode('introspection')
×
279
                            ->canBeDisabled()
×
280
                        ->end()
×
281
                        ->integerNode('max_query_depth')->defaultValue(20)
×
282
                        ->end()
×
283
                        ->arrayNode('graphql_playground')
×
284
                            ->setDeprecated('api-platform/core', '4.0')
×
285
                        ->end()
×
286
                        ->integerNode('max_query_complexity')->defaultValue(500)
×
287
                        ->end()
×
288
                        ->scalarNode('nesting_separator')->defaultValue('_')->info('The separator to use to filter nested fields.')->end()
×
289
                        ->arrayNode('collection')
×
290
                            ->addDefaultsIfNotSet()
×
291
                            ->children()
×
292
                                ->arrayNode('pagination')
×
293
                                    ->canBeDisabled()
×
294
                                ->end()
×
295
                            ->end()
×
296
                        ->end()
×
297
                    ->end()
×
298
                ->end()
×
299
            ->end();
×
300
    }
301

302
    private function addSwaggerSection(ArrayNodeDefinition $rootNode): void
303
    {
304
        $supportedVersions = [3];
×
305

306
        $rootNode
×
307
            ->children()
×
308
                ->arrayNode('swagger')
×
309
                    ->addDefaultsIfNotSet()
×
310
                    ->children()
×
311
                        ->booleanNode('persist_authorization')->defaultValue(false)->info('Persist the SwaggerUI Authorization in the localStorage.')->end()
×
312
                        ->arrayNode('versions')
×
313
                            ->info('The active versions of OpenAPI to be exported or used in Swagger UI. The first value is the default.')
×
314
                            ->defaultValue($supportedVersions)
×
315
                            ->beforeNormalization()
×
316
                                ->always(static function ($v): array {
×
317
                                    if (!\is_array($v)) {
×
318
                                        $v = [$v];
×
319
                                    }
320

321
                                    foreach ($v as &$version) {
×
322
                                        $version = (int) $version;
×
323
                                    }
324

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

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

444
    private function addMercureSection(ArrayNodeDefinition $rootNode): void
445
    {
446
        $rootNode
×
447
            ->children()
×
448
                ->arrayNode('mercure')
×
449
                    ->{class_exists(MercureBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
450
                    ->children()
×
451
                        ->scalarNode('hub_url')
×
452
                            ->defaultNull()
×
453
                            ->info('The URL sent in the Link HTTP header. If not set, will default to the URL for MercureBundle\'s default hub.')
×
454
                        ->end()
×
455
                        ->booleanNode('include_type')
×
456
                            ->defaultFalse()
×
457
                            ->info('Always include @type in updates (including delete ones).')
×
458
                        ->end()
×
459
                    ->end()
×
460
                ->end()
×
461
            ->end();
×
462
    }
463

464
    private function addMessengerSection(ArrayNodeDefinition $rootNode): void
465
    {
466
        $rootNode
×
467
            ->children()
×
468
                ->arrayNode('messenger')
×
469
                    ->{!class_exists(FullStack::class) && interface_exists(MessageBusInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
470
                ->end()
×
471
            ->end();
×
472
    }
473

474
    private function addElasticsearchSection(ArrayNodeDefinition $rootNode): void
475
    {
476
        $rootNode
×
477
            ->children()
×
478
                ->arrayNode('elasticsearch')
×
479
                    ->canBeEnabled()
×
480
                    ->addDefaultsIfNotSet()
×
481
                    ->validate()
×
482
                        ->ifTrue(static fn (array $v): bool => null !== ($v['ssl_ca_bundle'] ?? null) && false === ($v['ssl_verification'] ?? true))
×
483
                        ->thenInvalid('The "ssl_ca_bundle" and "ssl_verification: false" options cannot be used together. Either provide a CA bundle path or disable SSL verification, not both.')
×
484
                    ->end()
×
485
                    ->children()
×
486
                        ->booleanNode('enabled')
×
487
                            ->defaultFalse()
×
488
                            ->validate()
×
489
                                ->ifTrue()
×
490
                                ->then(static function (bool $v): bool {
×
491
                                    if (
492
                                        // ES v7
493
                                        !class_exists(\Elasticsearch\Client::class)
×
494
                                        // ES v8 and up
495
                                        && !class_exists(\Elastic\Elasticsearch\Client::class)
×
496
                                    ) {
497
                                        throw new InvalidConfigurationException('The elasticsearch/elasticsearch package is required for Elasticsearch support.');
×
498
                                    }
499

500
                                    return $v;
×
501
                                })
×
502
                            ->end()
×
503
                        ->end()
×
504
                        ->arrayNode('hosts')
×
505
                            ->beforeNormalization()->castToArray()->end()
×
506
                            ->defaultValue([])
×
507
                            ->prototype('scalar')->end()
×
508
                        ->end()
×
509
                        ->scalarNode('ssl_ca_bundle')
×
510
                            ->defaultNull()
×
511
                            ->info('Path to the SSL CA bundle file for Elasticsearch SSL verification.')
×
512
                        ->end()
×
513
                        ->booleanNode('ssl_verification')
×
514
                            ->defaultTrue()
×
515
                            ->info('Enable or disable SSL verification for Elasticsearch connections.')
×
516
                        ->end()
×
517
                    ->end()
×
518
                ->end()
×
519
            ->end();
×
520
    }
521

522
    private function addOpenApiSection(ArrayNodeDefinition $rootNode): void
523
    {
524
        $rootNode
×
525
            ->children()
×
526
                ->arrayNode('openapi')
×
527
                    ->addDefaultsIfNotSet()
×
528
                        ->children()
×
529
                        ->arrayNode('contact')
×
530
                        ->addDefaultsIfNotSet()
×
531
                            ->children()
×
532
                                ->scalarNode('name')->defaultNull()->info('The identifying name of the contact person/organization.')->end()
×
533
                                ->scalarNode('url')->defaultNull()->info('The URL pointing to the contact information. MUST be in the format of a URL.')->end()
×
534
                                ->scalarNode('email')->defaultNull()->info('The email address of the contact person/organization. MUST be in the format of an email address.')->end()
×
535
                            ->end()
×
536
                        ->end()
×
537
                        ->scalarNode('termsOfService')->defaultNull()->info('A URL to the Terms of Service for the API. MUST be in the format of a URL.')->end()
×
538
                        ->arrayNode('tags')
×
539
                            ->info('Global OpenApi tags overriding the default computed tags if specified.')
×
540
                            ->prototype('array')
×
541
                                ->children()
×
542
                                    ->scalarNode('name')->isRequired()->end()
×
543
                                    ->scalarNode('description')->defaultNull()->end()
×
544
                                ->end()
×
545
                            ->end()
×
546
                        ->end()
×
547
                        ->arrayNode('license')
×
548
                        ->addDefaultsIfNotSet()
×
549
                            ->children()
×
550
                                ->scalarNode('name')->defaultNull()->info('The license name used for the API.')->end()
×
551
                                ->scalarNode('url')->defaultNull()->info('URL to the license used for the API. MUST be in the format of a URL.')->end()
×
552
                                ->scalarNode('identifier')->defaultNull()->info('An SPDX license expression for the API. The identifier field is mutually exclusive of the url field.')->end()
×
553
                            ->end()
×
554
                        ->end()
×
555
                        ->variableNode('swagger_ui_extra_configuration')
×
556
                            ->defaultValue([])
×
557
                            ->validate()
×
558
                                ->ifTrue(static fn ($v): bool => false === \is_array($v))
×
559
                                ->thenInvalid('The swagger_ui_extra_configuration parameter must be an array.')
×
560
                            ->end()
×
561
                            ->info('To pass extra configuration to Swagger UI, like docExpansion or filter.')
×
562
                        ->end()
×
563
                        ->booleanNode('overrideResponses')->defaultTrue()->info('Whether API Platform adds automatic responses to the OpenAPI documentation.')->end()
×
564
                        ->scalarNode('error_resource_class')->defaultNull()->info('The class used to represent errors in the OpenAPI documentation.')->end()
×
565
                        ->scalarNode('validation_error_resource_class')->defaultNull()->info('The class used to represent validation errors in the OpenAPI documentation.')->end()
×
566
                    ->end()
×
567
                ->end()
×
568
            ->end();
×
569
    }
570

571
    /**
572
     * @throws InvalidConfigurationException
573
     */
574
    private function addExceptionToStatusSection(ArrayNodeDefinition $rootNode): void
575
    {
576
        $rootNode
×
577
            ->children()
×
578
                ->arrayNode('exception_to_status')
×
579
                    ->defaultValue([
×
580
                        SerializerExceptionInterface::class => Response::HTTP_BAD_REQUEST,
×
581
                        InvalidArgumentException::class => Response::HTTP_BAD_REQUEST,
×
582
                        OptimisticLockException::class => Response::HTTP_CONFLICT,
×
583
                    ])
×
584
                    ->info('The list of exceptions mapped to their HTTP status code.')
×
585
                    ->normalizeKeys(false)
×
586
                    ->useAttributeAsKey('exception_class')
×
587
                    ->prototype('integer')->end()
×
588
                    ->validate()
×
589
                        ->ifArray()
×
590
                        ->then(static function (array $exceptionToStatus): array {
×
591
                            foreach ($exceptionToStatus as $httpStatusCode) {
×
592
                                if ($httpStatusCode < 100 || $httpStatusCode >= 600) {
×
593
                                    throw new InvalidConfigurationException(sprintf('The HTTP status code "%s" is not valid.', $httpStatusCode));
×
594
                                }
595
                            }
596

597
                            return $exceptionToStatus;
×
598
                        })
×
599
                    ->end()
×
600
                ->end()
×
601
            ->end();
×
602
    }
603

604
    private function addFormatSection(ArrayNodeDefinition $rootNode, string $key, array $defaultValue): void
605
    {
606
        $rootNode
×
607
            ->children()
×
608
                ->arrayNode($key)
×
609
                    ->defaultValue($defaultValue)
×
610
                    ->info('The list of enabled formats. The first one will be the default.')
×
611
                    ->normalizeKeys(false)
×
612
                    ->useAttributeAsKey('format')
×
613
                    ->beforeNormalization()
×
614
                        ->ifArray()
×
615
                        ->then(static function ($v) {
×
616
                            foreach ($v as $format => $value) {
×
617
                                if (isset($value['mime_types'])) {
×
618
                                    continue;
×
619
                                }
620

621
                                $v[$format] = ['mime_types' => $value];
×
622
                            }
623

624
                            return $v;
×
625
                        })
×
626
                    ->end()
×
627
                    ->prototype('array')
×
628
                        ->children()
×
629
                            ->arrayNode('mime_types')->prototype('scalar')->end()->end()
×
630
                        ->end()
×
631
                    ->end()
×
632
                ->end()
×
633
            ->end();
×
634
    }
635

636
    private function addDefaultsSection(ArrayNodeDefinition $rootNode): void
637
    {
638
        $nameConverter = new CamelCaseToSnakeCaseNameConverter();
×
639
        $defaultsNode = $rootNode->children()->arrayNode('defaults');
×
640

641
        $defaultsNode
×
642
            ->ignoreExtraKeys(false)
×
643
            ->beforeNormalization()
×
644
            ->always(static function (array $defaults) use ($nameConverter): array {
×
645
                $normalizedDefaults = [];
×
646
                foreach ($defaults as $option => $value) {
×
647
                    $option = $nameConverter->normalize($option);
×
648
                    $normalizedDefaults[$option] = $value;
×
649
                }
650

651
                return $normalizedDefaults;
×
652
            });
×
653

654
        $this->defineDefault($defaultsNode, new \ReflectionClass(ApiResource::class), $nameConverter);
×
655
        $this->defineDefault($defaultsNode, new \ReflectionClass(Put::class), $nameConverter);
×
656
        $this->defineDefault($defaultsNode, new \ReflectionClass(Post::class), $nameConverter);
×
657
    }
658

659
    private function addMakerSection(ArrayNodeDefinition $rootNode): void
660
    {
661
        $rootNode
×
662
            ->children()
×
663
                ->arrayNode('maker')
×
664
                    ->{class_exists(MakerBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
665
                    ->children()
×
666
                        ->scalarNode('namespace_prefix')->defaultValue('')->info('Add a prefix to all maker generated classes. e.g set it to "Api" to set the maker namespace to "App\\Api\\" (if the maker.root_namespace config is App). e.g. App\\Api\\State\\MyStateProcessor')->end()
×
667
                    ->end()
×
668
                ->end()
×
669
            ->end();
×
670
    }
671

672
    private function defineDefault(ArrayNodeDefinition $defaultsNode, \ReflectionClass $reflectionClass, CamelCaseToSnakeCaseNameConverter $nameConverter): void
673
    {
674
        foreach ($reflectionClass->getConstructor()->getParameters() as $parameter) {
×
675
            $defaultsNode->children()->variableNode($nameConverter->normalize($parameter->getName()));
×
676
        }
677
    }
678
}
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

© 2026 Coveralls, Inc