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

api-platform / core / 18370496742

09 Oct 2025 08:35AM UTC coverage: 0.0% (-21.9%) from 21.92%
18370496742

push

github

soyuka
docs: changelog 4.2.2

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

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

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

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

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

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

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

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

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

211
        return $treeBuilder;
×
212
    }
213

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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