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

api-platform / core / 19192661240

08 Nov 2025 11:10AM UTC coverage: 0.0%. Remained the same
19192661240

push

github

soyuka
Merge remote-tracking branch 'upstream/4.1' into 4.2

0 of 56693 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')->defaultFalse()->info('Enable security for Links (sub resources)')->end()
×
121
                ->arrayNode('collection')
×
122
                    ->addDefaultsIfNotSet()
×
123
                    ->children()
×
124
                        ->scalarNode('exists_parameter_name')->defaultValue('exists')->cannotBeEmpty()->info('The name of the query parameter to filter on nullable field values.')->end()
×
125
                        ->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
×
126
                        ->scalarNode('order_parameter_name')->defaultValue('order')->cannotBeEmpty()->info('The name of the query parameter to order results.')->end()
×
127
                        ->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()
×
128
                        ->arrayNode('pagination')
×
129
                            ->canBeDisabled()
×
130
                            ->addDefaultsIfNotSet()
×
131
                            ->children()
×
132
                                ->scalarNode('page_parameter_name')->defaultValue('page')->cannotBeEmpty()->info('The default name of the parameter handling the page number.')->end()
×
133
                                ->scalarNode('enabled_parameter_name')->defaultValue('pagination')->cannotBeEmpty()->info('The name of the query parameter to enable or disable pagination.')->end()
×
134
                                ->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()
×
135
                                ->scalarNode('partial_parameter_name')->defaultValue('partial')->cannotBeEmpty()->info('The name of the query parameter to enable or disable partial pagination.')->end()
×
136
                            ->end()
×
137
                        ->end()
×
138
                    ->end()
×
139
                ->end()
×
140
                ->arrayNode('mapping')
×
141
                    ->addDefaultsIfNotSet()
×
142
                    ->children()
×
143
                        ->arrayNode('imports')
×
144
                            ->prototype('scalar')->end()
×
145
                        ->end()
×
146
                        ->arrayNode('paths')
×
147
                            ->prototype('scalar')->end()
×
148
                        ->end()
×
149
                    ->end()
×
150
                ->end()
×
151
                ->arrayNode('resource_class_directories')
×
152
                    ->prototype('scalar')->end()
×
153
                    ->setDeprecated('api-platform/symfony', '4.1', 'The "resource_class_directories" configuration is deprecated, classes using #[ApiResource] attribute are autoconfigured by the dependency injection container.')
×
154
                ->end()
×
155
                ->arrayNode('serializer')
×
156
                    ->addDefaultsIfNotSet()
×
157
                    ->children()
×
158
                        ->booleanNode('hydra_prefix')->defaultFalse()->info('Use the "hydra:" prefix.')->end()
×
159
                    ->end()
×
160
                ->end()
×
161
            ->end();
×
162

163
        $this->addDoctrineOrmSection($rootNode);
×
164
        $this->addDoctrineMongoDbOdmSection($rootNode);
×
165
        $this->addOAuthSection($rootNode);
×
166
        $this->addGraphQlSection($rootNode);
×
167
        $this->addSwaggerSection($rootNode);
×
168
        $this->addHttpCacheSection($rootNode);
×
169
        $this->addMercureSection($rootNode);
×
170
        $this->addMessengerSection($rootNode);
×
171
        $this->addElasticsearchSection($rootNode);
×
172
        $this->addOpenApiSection($rootNode);
×
173
        $this->addMakerSection($rootNode);
×
174

175
        $this->addExceptionToStatusSection($rootNode);
×
176

177
        $this->addFormatSection($rootNode, 'formats', [
×
178
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
179
        ]);
×
180
        $this->addFormatSection($rootNode, 'patch_formats', [
×
181
            'json' => ['mime_types' => ['application/merge-patch+json']],
×
182
        ]);
×
183

184
        $defaultDocFormats = [
×
185
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
186
            'jsonopenapi' => ['mime_types' => ['application/vnd.openapi+json']],
×
187
            'html' => ['mime_types' => ['text/html']],
×
188
        ];
×
189

190
        if (class_exists(Yaml::class)) {
×
191
            $defaultDocFormats['yamlopenapi'] = ['mime_types' => ['application/vnd.openapi+yaml']];
×
192
        }
193

194
        $this->addFormatSection($rootNode, 'docs_formats', $defaultDocFormats);
×
195

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

210
        $this->addDefaultsSection($rootNode);
×
211

212
        return $treeBuilder;
×
213
    }
214

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

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

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

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

298
    private function addSwaggerSection(ArrayNodeDefinition $rootNode): void
299
    {
300
        $supportedVersions = [3];
×
301

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

317
                                    foreach ($v as &$version) {
×
318
                                        $version = (int) $version;
×
319
                                    }
320

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

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

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

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

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

492
                                    return $v;
×
493
                                })
×
494
                            ->end()
×
495
                        ->end()
×
496
                        ->arrayNode('hosts')
×
497
                            ->beforeNormalization()->castToArray()->end()
×
498
                            ->defaultValue([])
×
499
                            ->prototype('scalar')->end()
×
500
                        ->end()
×
501
                    ->end()
×
502
                ->end()
×
503
            ->end();
×
504
    }
505

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

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

581
                            return $exceptionToStatus;
×
582
                        })
×
583
                    ->end()
×
584
                ->end()
×
585
            ->end();
×
586
    }
587

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

605
                                $v[$format] = ['mime_types' => $value];
×
606
                            }
607

608
                            return $v;
×
609
                        })
×
610
                    ->end()
×
611
                    ->prototype('array')
×
612
                        ->children()
×
613
                            ->arrayNode('mime_types')->prototype('scalar')->end()->end()
×
614
                        ->end()
×
615
                    ->end()
×
616
                ->end()
×
617
            ->end();
×
618
    }
619

620
    private function addDefaultsSection(ArrayNodeDefinition $rootNode): void
621
    {
622
        $nameConverter = new CamelCaseToSnakeCaseNameConverter();
×
623
        $defaultsNode = $rootNode->children()->arrayNode('defaults');
×
624

625
        $defaultsNode
×
626
            ->ignoreExtraKeys(false)
×
627
            ->beforeNormalization()
×
628
            ->always(static function (array $defaults) use ($nameConverter): array {
×
629
                $normalizedDefaults = [];
×
630
                foreach ($defaults as $option => $value) {
×
631
                    $option = $nameConverter->normalize($option);
×
632
                    $normalizedDefaults[$option] = $value;
×
633
                }
634

635
                return $normalizedDefaults;
×
636
            });
×
637

638
        $this->defineDefault($defaultsNode, new \ReflectionClass(ApiResource::class), $nameConverter);
×
639
        $this->defineDefault($defaultsNode, new \ReflectionClass(Put::class), $nameConverter);
×
640
        $this->defineDefault($defaultsNode, new \ReflectionClass(Post::class), $nameConverter);
×
641
    }
642

643
    private function addMakerSection(ArrayNodeDefinition $rootNode): void
644
    {
645
        $rootNode
×
646
            ->children()
×
647
                ->arrayNode('maker')
×
648
                    ->{class_exists(MakerBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
649
                ->end()
×
650
            ->end();
×
651
    }
652

653
    private function defineDefault(ArrayNodeDefinition $defaultsNode, \ReflectionClass $reflectionClass, CamelCaseToSnakeCaseNameConverter $nameConverter): void
654
    {
655
        foreach ($reflectionClass->getConstructor()->getParameters() as $parameter) {
×
656
            $defaultsNode->children()->variableNode($nameConverter->normalize($parameter->getName()));
×
657
        }
658
    }
659
}
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