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

api-platform / core / 10027319583

21 Jul 2024 09:36AM UTC coverage: 7.847%. Remained the same
10027319583

push

github

web-flow
ci: fix naming of Windows Behat matrix line (#6489)

12688 of 161690 relevant lines covered (7.85%)

26.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.33
/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\Elasticsearch\State\Options;
18
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
19
use ApiPlatform\Metadata\ApiResource;
20
use ApiPlatform\Metadata\Post;
21
use ApiPlatform\Metadata\Put;
22
use ApiPlatform\Symfony\Controller\MainController;
23
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
24
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
25
use Doctrine\ORM\EntityManagerInterface;
26
use Doctrine\ORM\OptimisticLockException;
27
use GraphQL\GraphQL;
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\Messenger\MessageBusInterface;
38
use Symfony\Component\Serializer\Exception\ExceptionInterface as SerializerExceptionInterface;
39
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
40

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

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

65
                    return $v;
3✔
66
                })
57✔
67
            ->end()
57✔
68
            ->children()
57✔
69
                ->scalarNode('title')
57✔
70
                    ->info('The title of the API.')
57✔
71
                    ->cannotBeEmpty()
57✔
72
                    ->defaultValue('')
57✔
73
                ->end()
57✔
74
                ->scalarNode('description')
57✔
75
                    ->info('The description of the API.')
57✔
76
                    ->cannotBeEmpty()
57✔
77
                    ->defaultValue('')
57✔
78
                ->end()
57✔
79
                ->scalarNode('version')
57✔
80
                    ->info('The version of the API.')
57✔
81
                    ->cannotBeEmpty()
57✔
82
                    ->defaultValue('0.0.0')
57✔
83
                ->end()
57✔
84
                ->booleanNode('show_webby')->defaultTrue()->info('If true, show Webby on the documentation page')->end()
57✔
85
                ->booleanNode('use_symfony_listeners')->defaultFalse()->info(sprintf('Uses Symfony event listeners instead of the %s.', MainController::class))->end()
57✔
86
                ->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end()
57✔
87
                ->scalarNode('asset_package')->defaultNull()->info('Specify an asset package name to use.')->end()
57✔
88
                ->scalarNode('path_segment_name_generator')->defaultValue('api_platform.metadata.path_segment_name_generator.underscore')->info('Specify a path name generator to use.')->end()
57✔
89
                ->scalarNode('inflector')->defaultValue('api_platform.metadata.inflector')->info('Specify an inflector to use.')->end()
57✔
90
                ->arrayNode('validator')
57✔
91
                    ->addDefaultsIfNotSet()
57✔
92
                    ->children()
57✔
93
                        ->variableNode('serialize_payload_fields')->defaultValue([])->info('Set to null to serialize all payload fields when a validation error is thrown, or set the fields you want to include explicitly.')->end()
57✔
94
                        ->booleanNode('query_parameter_validation')->defaultValue(true)->end()
57✔
95
                    ->end()
57✔
96
                ->end()
57✔
97
                ->arrayNode('eager_loading')
57✔
98
                    ->canBeDisabled()
57✔
99
                    ->addDefaultsIfNotSet()
57✔
100
                    ->children()
57✔
101
                        ->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()
57✔
102
                        ->integerNode('max_joins')->defaultValue(30)->info('Max number of joined relations before EagerLoading throws a RuntimeException')->end()
57✔
103
                        ->booleanNode('force_eager')->defaultTrue()->info('Force join on every relation. If disabled, it will only join relations having the EAGER fetch mode.')->end()
57✔
104
                    ->end()
57✔
105
                ->end()
57✔
106
                ->booleanNode('handle_symfony_errors')->defaultFalse()->info('Allows to handle symfony exceptions.')->end()
57✔
107
                ->booleanNode('enable_swagger')->defaultTrue()->info('Enable the Swagger documentation and export.')->end()
57✔
108
                ->booleanNode('enable_swagger_ui')->defaultValue(class_exists(TwigBundle::class))->info('Enable Swagger UI')->end()
57✔
109
                ->booleanNode('enable_re_doc')->defaultValue(class_exists(TwigBundle::class))->info('Enable ReDoc')->end()
57✔
110
                ->booleanNode('enable_entrypoint')->defaultTrue()->info('Enable the entrypoint')->end()
57✔
111
                ->booleanNode('enable_docs')->defaultTrue()->info('Enable the docs')->end()
57✔
112
                ->booleanNode('enable_profiler')->defaultTrue()->info('Enable the data collector and the WebProfilerBundle integration.')->end()
57✔
113
                ->booleanNode('enable_link_security')->defaultFalse()->info('Enable security for Links (sub resources)')->end()
57✔
114
                ->arrayNode('collection')
57✔
115
                    ->addDefaultsIfNotSet()
57✔
116
                    ->children()
57✔
117
                        ->scalarNode('exists_parameter_name')->defaultValue('exists')->cannotBeEmpty()->info('The name of the query parameter to filter on nullable field values.')->end()
57✔
118
                        ->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
57✔
119
                        ->scalarNode('order_parameter_name')->defaultValue('order')->cannotBeEmpty()->info('The name of the query parameter to order results.')->end()
57✔
120
                        ->enumNode('order_nulls_comparison')->defaultNull()->values(array_merge(array_keys(OrderFilterInterface::NULLS_DIRECTION_MAP), [null]))->info('The nulls comparison strategy.')->end()
57✔
121
                        ->arrayNode('pagination')
57✔
122
                            ->canBeDisabled()
57✔
123
                            ->addDefaultsIfNotSet()
57✔
124
                            ->children()
57✔
125
                                ->scalarNode('page_parameter_name')->defaultValue('page')->cannotBeEmpty()->info('The default name of the parameter handling the page number.')->end()
57✔
126
                                ->scalarNode('enabled_parameter_name')->defaultValue('pagination')->cannotBeEmpty()->info('The name of the query parameter to enable or disable pagination.')->end()
57✔
127
                                ->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()
57✔
128
                                ->scalarNode('partial_parameter_name')->defaultValue('partial')->cannotBeEmpty()->info('The name of the query parameter to enable or disable partial pagination.')->end()
57✔
129
                            ->end()
57✔
130
                        ->end()
57✔
131
                    ->end()
57✔
132
                ->end()
57✔
133
                ->arrayNode('mapping')
57✔
134
                    ->addDefaultsIfNotSet()
57✔
135
                    ->children()
57✔
136
                        ->arrayNode('paths')
57✔
137
                            ->prototype('scalar')->end()
57✔
138
                        ->end()
57✔
139
                    ->end()
57✔
140
                ->end()
57✔
141
                ->arrayNode('resource_class_directories')
57✔
142
                    ->prototype('scalar')->end()
57✔
143
                ->end()
57✔
144
            ->end();
57✔
145

146
        $this->addDoctrineOrmSection($rootNode);
57✔
147
        $this->addDoctrineMongoDbOdmSection($rootNode);
57✔
148
        $this->addOAuthSection($rootNode);
57✔
149
        $this->addGraphQlSection($rootNode);
57✔
150
        $this->addSwaggerSection($rootNode);
57✔
151
        $this->addHttpCacheSection($rootNode);
57✔
152
        $this->addMercureSection($rootNode);
57✔
153
        $this->addMessengerSection($rootNode);
57✔
154
        $this->addElasticsearchSection($rootNode);
57✔
155
        $this->addOpenApiSection($rootNode);
57✔
156
        $this->addMakerSection($rootNode);
57✔
157

158
        $this->addExceptionToStatusSection($rootNode);
57✔
159

160
        $this->addFormatSection($rootNode, 'formats', [
57✔
161
        ]);
57✔
162
        $this->addFormatSection($rootNode, 'patch_formats', [
57✔
163
            'json' => ['mime_types' => ['application/merge-patch+json']],
57✔
164
        ]);
57✔
165
        $this->addFormatSection($rootNode, 'docs_formats', [
57✔
166
            'jsonopenapi' => ['mime_types' => ['application/vnd.openapi+json']],
57✔
167
            'yamlopenapi' => ['mime_types' => ['application/vnd.openapi+yaml']],
57✔
168
            'jsonld' => ['mime_types' => ['application/ld+json']],
57✔
169
            'html' => ['mime_types' => ['text/html']],
57✔
170
        ]);
57✔
171
        $this->addFormatSection($rootNode, 'error_formats', [
57✔
172
            'jsonld' => ['mime_types' => ['application/ld+json']],
57✔
173
            'jsonproblem' => ['mime_types' => ['application/problem+json']],
57✔
174
            'json' => ['mime_types' => ['application/problem+json', 'application/json']],
57✔
175
        ]);
57✔
176
        $rootNode
57✔
177
            ->children()
57✔
178
                ->arrayNode('jsonschema_formats')
57✔
179
                    ->scalarPrototype()->end()
57✔
180
                    ->defaultValue([])
57✔
181
                    ->info('The JSON formats to compute the JSON Schemas for.')
57✔
182
                ->end()
57✔
183
            ->end();
57✔
184

185
        $this->addDefaultsSection($rootNode);
57✔
186

187
        return $treeBuilder;
57✔
188
    }
189

190
    private function addDoctrineOrmSection(ArrayNodeDefinition $rootNode): void
191
    {
192
        $rootNode
57✔
193
            ->children()
57✔
194
                ->arrayNode('doctrine')
57✔
195
                    ->{class_exists(DoctrineBundle::class) && interface_exists(EntityManagerInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
57✔
196
                ->end()
57✔
197
            ->end();
57✔
198
    }
199

200
    private function addDoctrineMongoDbOdmSection(ArrayNodeDefinition $rootNode): void
201
    {
202
        $rootNode
57✔
203
            ->children()
57✔
204
                ->arrayNode('doctrine_mongodb_odm')
57✔
205
                    ->{class_exists(DoctrineMongoDBBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
57✔
206
                ->end()
57✔
207
            ->end();
57✔
208
    }
209

210
    private function addOAuthSection(ArrayNodeDefinition $rootNode): void
211
    {
212
        $rootNode
57✔
213
            ->children()
57✔
214
                ->arrayNode('oauth')
57✔
215
                    ->canBeEnabled()
57✔
216
                    ->addDefaultsIfNotSet()
57✔
217
                    ->children()
57✔
218
                        ->scalarNode('clientId')->defaultValue('')->info('The oauth client id.')->end()
57✔
219
                        ->scalarNode('clientSecret')
57✔
220
                            ->defaultValue('')
57✔
221
                            ->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')
57✔
222
                        ->end()
57✔
223
                        ->booleanNode('pkce')->defaultFalse()->info('Enable the oauth PKCE.')->end()
57✔
224
                        ->scalarNode('type')->defaultValue('oauth2')->info('The oauth type.')->end()
57✔
225
                        ->scalarNode('flow')->defaultValue('application')->info('The oauth flow grant type.')->end()
57✔
226
                        ->scalarNode('tokenUrl')->defaultValue('')->info('The oauth token url.')->end()
57✔
227
                        ->scalarNode('authorizationUrl')->defaultValue('')->info('The oauth authentication url.')->end()
57✔
228
                        ->scalarNode('refreshUrl')->defaultValue('')->info('The oauth refresh url.')->end()
57✔
229
                        ->arrayNode('scopes')
57✔
230
                            ->prototype('scalar')->end()
57✔
231
                        ->end()
57✔
232
                    ->end()
57✔
233
                ->end()
57✔
234
            ->end();
57✔
235
    }
236

237
    private function addGraphQlSection(ArrayNodeDefinition $rootNode): void
238
    {
239
        $rootNode
57✔
240
            ->children()
57✔
241
                ->arrayNode('graphql')
57✔
242
                    ->{class_exists(GraphQL::class) ? 'canBeDisabled' : 'canBeEnabled'}()
57✔
243
                    ->addDefaultsIfNotSet()
57✔
244
                    ->children()
57✔
245
                        ->scalarNode('default_ide')->defaultValue('graphiql')->end()
57✔
246
                        ->arrayNode('graphiql')
57✔
247
                            ->{class_exists(GraphQL::class) && class_exists(TwigBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
57✔
248
                        ->end()
57✔
249
                        ->arrayNode('graphql_playground')
57✔
250
                            ->{class_exists(GraphQL::class) && class_exists(TwigBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
57✔
251
                        ->end()
57✔
252
                        ->arrayNode('introspection')
57✔
253
                            ->canBeDisabled()
57✔
254
                        ->end()
57✔
255
                        ->scalarNode('nesting_separator')->defaultValue('_')->info('The separator to use to filter nested fields.')->end()
57✔
256
                        ->arrayNode('collection')
57✔
257
                            ->addDefaultsIfNotSet()
57✔
258
                            ->children()
57✔
259
                                ->arrayNode('pagination')
57✔
260
                                    ->canBeDisabled()
57✔
261
                                ->end()
57✔
262
                            ->end()
57✔
263
                        ->end()
57✔
264
                    ->end()
57✔
265
                ->end()
57✔
266
            ->end();
57✔
267
    }
268

269
    private function addSwaggerSection(ArrayNodeDefinition $rootNode): void
270
    {
271
        $supportedVersions = [3];
57✔
272

273
        $rootNode
57✔
274
            ->children()
57✔
275
                ->arrayNode('swagger')
57✔
276
                    ->addDefaultsIfNotSet()
57✔
277
                    ->children()
57✔
278
                        ->arrayNode('versions')
57✔
279
                            ->info('The active versions of OpenAPI to be exported or used in Swagger UI. The first value is the default.')
57✔
280
                            ->defaultValue($supportedVersions)
57✔
281
                            ->beforeNormalization()
57✔
282
                                ->always(static function ($v): array {
57✔
283
                                    if (!\is_array($v)) {
6✔
284
                                        $v = [$v];
×
285
                                    }
286

287
                                    foreach ($v as &$version) {
6✔
288
                                        $version = (int) $version;
3✔
289
                                    }
290

291
                                    return $v;
6✔
292
                                })
57✔
293
                            ->end()
57✔
294
                            ->validate()
57✔
295
                                ->ifTrue(static fn ($v): bool => $v !== array_intersect($v, $supportedVersions))
57✔
296
                                ->thenInvalid(sprintf('Only the versions %s are supported. Got %s.', implode(' and ', $supportedVersions), '%s'))
57✔
297
                            ->end()
57✔
298
                            ->prototype('scalar')->end()
57✔
299
                        ->end()
57✔
300
                        ->arrayNode('api_keys')
57✔
301
                            ->useAttributeAsKey('key')
57✔
302
                            ->validate()
57✔
303
                                ->ifTrue(static fn ($v): bool => (bool) array_filter(array_keys($v), fn ($item) => !preg_match('/^[a-zA-Z0-9._-]+$/', $item)))
57✔
304
                                ->thenInvalid('The api keys "key" is not valid according to the pattern enforced by OpenAPI 3.1 ^[a-zA-Z0-9._-]+$.')
57✔
305
                            ->end()
57✔
306
                            ->prototype('array')
57✔
307
                                ->children()
57✔
308
                                    ->scalarNode('name')
57✔
309
                                        ->info('The name of the header or query parameter containing the api key.')
57✔
310
                                    ->end()
57✔
311
                                    ->enumNode('type')
57✔
312
                                        ->info('Whether the api key should be a query parameter or a header.')
57✔
313
                                        ->values(['query', 'header'])
57✔
314
                                    ->end()
57✔
315
                                ->end()
57✔
316
                            ->end()
57✔
317
                        ->end()
57✔
318
                        ->variableNode('swagger_ui_extra_configuration')
57✔
319
                            ->defaultValue([])
57✔
320
                            ->validate()
57✔
321
                                ->ifTrue(static fn ($v): bool => false === \is_array($v))
57✔
322
                                ->thenInvalid('The swagger_ui_extra_configuration parameter must be an array.')
57✔
323
                            ->end()
57✔
324
                            ->info('To pass extra configuration to Swagger UI, like docExpansion or filter.')
57✔
325
                        ->end()
57✔
326
                    ->end()
57✔
327
                ->end()
57✔
328
            ->end();
57✔
329
    }
330

331
    private function addHttpCacheSection(ArrayNodeDefinition $rootNode): void
332
    {
333
        $rootNode
57✔
334
            ->children()
57✔
335
                ->arrayNode('http_cache')
57✔
336
                    ->addDefaultsIfNotSet()
57✔
337
                    ->children()
57✔
338
                        ->booleanNode('public')->defaultNull()->info('To make all responses public by default.')->end()
57✔
339
                        ->arrayNode('invalidation')
57✔
340
                            ->info('Enable the tags-based cache invalidation system.')
57✔
341
                            ->canBeEnabled()
57✔
342
                            ->children()
57✔
343
                                ->arrayNode('varnish_urls')
57✔
344
                                    ->setDeprecated('api-platform/core', '3.0', 'The "varnish_urls" configuration is deprecated, use "urls" or "scoped_clients".')
57✔
345
                                    ->defaultValue([])
57✔
346
                                    ->prototype('scalar')->end()
57✔
347
                                    ->info('URLs of the Varnish servers to purge using cache tags when a resource is updated.')
57✔
348
                                ->end()
57✔
349
                                ->arrayNode('urls')
57✔
350
                                    ->defaultValue([])
57✔
351
                                    ->prototype('scalar')->end()
57✔
352
                                    ->info('URLs of the Varnish servers to purge using cache tags when a resource is updated.')
57✔
353
                                ->end()
57✔
354
                                ->arrayNode('scoped_clients')
57✔
355
                                    ->defaultValue([])
57✔
356
                                    ->prototype('scalar')->end()
57✔
357
                                    ->info('Service names of scoped client to use by the cache purger.')
57✔
358
                                ->end()
57✔
359
                                ->integerNode('max_header_length')
57✔
360
                                    ->defaultValue(7500)
57✔
361
                                    ->info('Max header length supported by the cache server.')
57✔
362
                                ->end()
57✔
363
                                ->variableNode('request_options')
57✔
364
                                    ->defaultValue([])
57✔
365
                                    ->validate()
57✔
366
                                        ->ifTrue(static fn ($v): bool => false === \is_array($v))
57✔
367
                                        ->thenInvalid('The request_options parameter must be an array.')
57✔
368
                                    ->end()
57✔
369
                                    ->info('To pass options to the client charged with the request.')
57✔
370
                                ->end()
57✔
371
                                ->scalarNode('purger')
57✔
372
                                    ->defaultValue('api_platform.http_cache.purger.varnish')
57✔
373
                                    ->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").')
57✔
374
                                ->end()
57✔
375
                                ->arrayNode('xkey')
57✔
376
                                    ->setDeprecated('api-platform/core', '3.0', 'The "xkey" configuration is deprecated, use your own purger to customize surrogate keys or the appropriate paramters.')
57✔
377
                                    ->addDefaultsIfNotSet()
57✔
378
                                    ->children()
57✔
379
                                        ->scalarNode('glue')
57✔
380
                                        ->defaultValue(' ')
57✔
381
                                        ->info('xkey glue between keys')
57✔
382
                                        ->end()
57✔
383
                                    ->end()
57✔
384
                                ->end()
57✔
385
                            ->end()
57✔
386
                        ->end()
57✔
387
                    ->end()
57✔
388
                ->end()
57✔
389
            ->end();
57✔
390
    }
391

392
    private function addMercureSection(ArrayNodeDefinition $rootNode): void
393
    {
394
        $rootNode
57✔
395
            ->children()
57✔
396
                ->arrayNode('mercure')
57✔
397
                    ->{class_exists(MercureBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
57✔
398
                    ->children()
57✔
399
                        ->scalarNode('hub_url')
57✔
400
                            ->defaultNull()
57✔
401
                            ->info('The URL sent in the Link HTTP header. If not set, will default to the URL for MercureBundle\'s default hub.')
57✔
402
                        ->end()
57✔
403
                        ->booleanNode('include_type')
57✔
404
                            ->defaultFalse()
57✔
405
                            ->info('Always include @type in updates (including delete ones).')
57✔
406
                        ->end()
57✔
407
                    ->end()
57✔
408
                ->end()
57✔
409
            ->end();
57✔
410
    }
411

412
    private function addMessengerSection(ArrayNodeDefinition $rootNode): void
413
    {
414
        $rootNode
57✔
415
            ->children()
57✔
416
                ->arrayNode('messenger')
57✔
417
                    ->{!class_exists(FullStack::class) && interface_exists(MessageBusInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
57✔
418
                ->end()
57✔
419
            ->end();
57✔
420
    }
421

422
    private function addElasticsearchSection(ArrayNodeDefinition $rootNode): void
423
    {
424
        $rootNode
57✔
425
            ->children()
57✔
426
                ->arrayNode('elasticsearch')
57✔
427
                    ->canBeEnabled()
57✔
428
                    ->addDefaultsIfNotSet()
57✔
429
                    ->children()
57✔
430
                        ->booleanNode('enabled')
57✔
431
                            ->defaultFalse()
57✔
432
                            ->validate()
57✔
433
                                ->ifTrue()
57✔
434
                                ->then(static function (bool $v): bool {
57✔
435
                                    if (!(class_exists(\Elasticsearch\Client::class) || class_exists(\Elastic\Elasticsearch\Client::class))) {
3✔
436
                                        throw new InvalidConfigurationException('The elasticsearch/elasticsearch package is required for Elasticsearch support.');
×
437
                                    }
438

439
                                    return $v;
3✔
440
                                })
57✔
441
                            ->end()
57✔
442
                        ->end()
57✔
443
                        ->arrayNode('hosts')
57✔
444
                            ->beforeNormalization()->castToArray()->end()
57✔
445
                            ->defaultValue([])
57✔
446
                            ->prototype('scalar')->end()
57✔
447
                        ->end()
57✔
448
                    ->end()
57✔
449
                ->end()
57✔
450
            ->end();
57✔
451
    }
452

453
    private function addOpenApiSection(ArrayNodeDefinition $rootNode): void
454
    {
455
        $rootNode
57✔
456
            ->children()
57✔
457
                ->arrayNode('openapi')
57✔
458
                    ->addDefaultsIfNotSet()
57✔
459
                        ->children()
57✔
460
                        ->arrayNode('contact')
57✔
461
                        ->addDefaultsIfNotSet()
57✔
462
                            ->children()
57✔
463
                                ->scalarNode('name')->defaultNull()->info('The identifying name of the contact person/organization.')->end()
57✔
464
                                ->scalarNode('url')->defaultNull()->info('The URL pointing to the contact information. MUST be in the format of a URL.')->end()
57✔
465
                                ->scalarNode('email')->defaultNull()->info('The email address of the contact person/organization. MUST be in the format of an email address.')->end()
57✔
466
                            ->end()
57✔
467
                        ->end()
57✔
468
                        ->scalarNode('termsOfService')->defaultNull()->info('A URL to the Terms of Service for the API. MUST be in the format of a URL.')->end()
57✔
469
                        ->arrayNode('license')
57✔
470
                        ->addDefaultsIfNotSet()
57✔
471
                            ->children()
57✔
472
                                ->scalarNode('name')->defaultNull()->info('The license name used for the API.')->end()
57✔
473
                                ->scalarNode('url')->defaultNull()->info('URL to the license used for the API. MUST be in the format of a URL.')->end()
57✔
474
                            ->end()
57✔
475
                        ->end()
57✔
476
                        ->variableNode('swagger_ui_extra_configuration')
57✔
477
                            ->defaultValue([])
57✔
478
                            ->validate()
57✔
479
                                ->ifTrue(static fn ($v): bool => false === \is_array($v))
57✔
480
                                ->thenInvalid('The swagger_ui_extra_configuration parameter must be an array.')
57✔
481
                            ->end()
57✔
482
                            ->info('To pass extra configuration to Swagger UI, like docExpansion or filter.')
57✔
483
                        ->end()
57✔
484
                        ->booleanNode('overrideResponses')->defaultTrue()->info('Whether API Platform adds automatic responses to the OpenAPI documentation.')
57✔
485
                    ->end()
57✔
486
                ->end()
57✔
487
            ->end();
57✔
488
    }
489

490
    /**
491
     * @throws InvalidConfigurationException
492
     */
493
    private function addExceptionToStatusSection(ArrayNodeDefinition $rootNode): void
494
    {
495
        $rootNode
57✔
496
            ->children()
57✔
497
                ->arrayNode('exception_to_status')
57✔
498
                    ->defaultValue([
57✔
499
                        SerializerExceptionInterface::class => Response::HTTP_BAD_REQUEST,
57✔
500
                        InvalidArgumentException::class => Response::HTTP_BAD_REQUEST,
57✔
501
                        OptimisticLockException::class => Response::HTTP_CONFLICT,
57✔
502
                    ])
57✔
503
                    ->info('The list of exceptions mapped to their HTTP status code.')
57✔
504
                    ->normalizeKeys(false)
57✔
505
                    ->useAttributeAsKey('exception_class')
57✔
506
                    ->prototype('integer')->end()
57✔
507
                    ->validate()
57✔
508
                        ->ifArray()
57✔
509
                        ->then(static function (array $exceptionToStatus): array {
57✔
510
                            foreach ($exceptionToStatus as $httpStatusCode) {
15✔
511
                                if ($httpStatusCode < 100 || $httpStatusCode >= 600) {
15✔
512
                                    throw new InvalidConfigurationException(sprintf('The HTTP status code "%s" is not valid.', $httpStatusCode));
12✔
513
                                }
514
                            }
515

516
                            return $exceptionToStatus;
3✔
517
                        })
57✔
518
                    ->end()
57✔
519
                ->end()
57✔
520
            ->end();
57✔
521
    }
522

523
    private function addFormatSection(ArrayNodeDefinition $rootNode, string $key, array $defaultValue): void
524
    {
525
        $rootNode
57✔
526
            ->children()
57✔
527
                ->arrayNode($key)
57✔
528
                    ->defaultValue($defaultValue)
57✔
529
                    ->info('The list of enabled formats. The first one will be the default.')
57✔
530
                    ->normalizeKeys(false)
57✔
531
                    ->useAttributeAsKey('format')
57✔
532
                    ->beforeNormalization()
57✔
533
                        ->ifArray()
57✔
534
                        ->then(static function ($v) {
57✔
535
                            foreach ($v as $format => $value) {
3✔
536
                                if (isset($value['mime_types'])) {
3✔
537
                                    continue;
×
538
                                }
539

540
                                $v[$format] = ['mime_types' => $value];
3✔
541
                            }
542

543
                            return $v;
3✔
544
                        })
57✔
545
                    ->end()
57✔
546
                    ->prototype('array')
57✔
547
                        ->children()
57✔
548
                            ->arrayNode('mime_types')->prototype('scalar')->end()->end()
57✔
549
                        ->end()
57✔
550
                    ->end()
57✔
551
                ->end()
57✔
552
            ->end();
57✔
553
    }
554

555
    private function addDefaultsSection(ArrayNodeDefinition $rootNode): void
556
    {
557
        $nameConverter = new CamelCaseToSnakeCaseNameConverter();
57✔
558
        $defaultsNode = $rootNode->children()->arrayNode('defaults');
57✔
559

560
        $defaultsNode
57✔
561
            ->ignoreExtraKeys(false)
57✔
562
            ->beforeNormalization()
57✔
563
            ->always(static function (array $defaults) use ($nameConverter): array {
57✔
564
                $normalizedDefaults = [];
3✔
565
                foreach ($defaults as $option => $value) {
3✔
566
                    $option = $nameConverter->normalize($option);
3✔
567
                    $normalizedDefaults[$option] = $value;
3✔
568
                }
569

570
                return $normalizedDefaults;
3✔
571
            });
57✔
572

573
        $this->defineDefault($defaultsNode, new \ReflectionClass(ApiResource::class), $nameConverter);
57✔
574
        $this->defineDefault($defaultsNode, new \ReflectionClass(Put::class), $nameConverter);
57✔
575
        $this->defineDefault($defaultsNode, new \ReflectionClass(Post::class), $nameConverter);
57✔
576
    }
577

578
    private function addMakerSection(ArrayNodeDefinition $rootNode): void
579
    {
580
        $rootNode
57✔
581
            ->children()
57✔
582
                ->arrayNode('maker')
57✔
583
                    ->{class_exists(MakerBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
57✔
584
                ->end()
57✔
585
            ->end();
57✔
586
    }
587

588
    private function defineDefault(ArrayNodeDefinition $defaultsNode, \ReflectionClass $reflectionClass, CamelCaseToSnakeCaseNameConverter $nameConverter): void
589
    {
590
        foreach ($reflectionClass->getConstructor()->getParameters() as $parameter) {
57✔
591
            $defaultsNode->children()->variableNode($nameConverter->normalize($parameter->getName()));
57✔
592
        }
593
    }
594
}
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