|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the API Platform project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Kévin Dunglas <[email protected]> |
|
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
|
|
|
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
15
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The configuration of the bundle. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Kévin Dunglas <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
final class Configuration implements ConfigurationInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getConfigTreeBuilder() |
|
28
|
|
|
{ |
|
29
|
|
|
$treeBuilder = new TreeBuilder(); |
|
30
|
|
|
$rootNode = $treeBuilder->root('api_platform'); |
|
31
|
|
|
|
|
32
|
|
|
$rootNode |
|
33
|
|
|
->children() |
|
34
|
|
|
->scalarNode('title')->defaultValue('')->info('The title of the API.')->end() |
|
35
|
|
|
->scalarNode('description')->defaultValue('')->info('The description of the API.')->end() |
|
36
|
|
|
->arrayNode('supported_formats') |
|
37
|
|
|
->defaultValue(['jsonld' => ['mime_types' => ['application/ld+json']]]) |
|
38
|
|
|
->info('The list of enabled formats. The first one will be the default.') |
|
39
|
|
|
->normalizeKeys(false) |
|
40
|
|
|
->useAttributeAsKey('format') |
|
41
|
|
|
->beforeNormalization() |
|
42
|
|
|
->ifArray() |
|
43
|
|
|
->then(function ($v) { |
|
44
|
|
|
foreach ($v as $format => $value) { |
|
45
|
|
|
if (isset($value['mime_types'])) { |
|
46
|
|
|
continue; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$v[$format] = ['mime_types' => $value]; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $v; |
|
53
|
|
|
}) |
|
54
|
|
|
->end() |
|
55
|
|
|
->prototype('array') |
|
56
|
|
|
->children() |
|
57
|
|
|
->arrayNode('mime_types')->prototype('scalar')->end()->end() |
|
58
|
|
|
->end() |
|
59
|
|
|
->end() |
|
60
|
|
|
->end() |
|
61
|
|
|
->arrayNode('routing') |
|
62
|
|
|
->addDefaultsIfNotSet() |
|
63
|
|
|
->children() |
|
64
|
|
|
->scalarNode('resource_path_generator')->defaultValue('api_platform.routing.resource_path_generator.underscore')->info('Specify the strategy to use for generating resource paths.')->end() |
|
65
|
|
|
->end() |
|
66
|
|
|
->end() |
|
67
|
|
|
->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end() |
|
68
|
|
|
->booleanNode('enable_fos_user')->defaultValue(false)->info('Enable the FOSUserBundle integration.')->end() |
|
69
|
|
|
->booleanNode('enable_nelmio_api_doc')->defaultTrue()->info('Enable the Nelmio Api doc integration.')->end() |
|
70
|
|
|
->arrayNode('collection') |
|
71
|
|
|
->addDefaultsIfNotSet() |
|
72
|
|
|
->children() |
|
73
|
|
|
->scalarNode('order')->defaultNull()->info('The default order of results.')->end() |
|
74
|
|
|
->scalarNode('order_parameter_name')->defaultValue('order')->cannotBeEmpty()->info('The name of the query parameter to order results.')->end() |
|
75
|
|
|
->arrayNode('pagination') |
|
76
|
|
|
->canBeDisabled() |
|
77
|
|
|
->addDefaultsIfNotSet() |
|
78
|
|
|
->children() |
|
79
|
|
|
->booleanNode('enabled')->defaultTrue()->info('To enable or disable pagination for all resource collections by default.')->end() |
|
80
|
|
|
->booleanNode('client_enabled')->defaultFalse()->info('To allow the client to enable or disable the pagination.')->end() |
|
81
|
|
|
->booleanNode('client_items_per_page')->defaultFalse()->info('To allow the client to set the number of items per page.')->end() |
|
82
|
|
|
->integerNode('items_per_page')->defaultValue(30)->info('The default number of items per page.')->end() |
|
83
|
|
|
->scalarNode('page_parameter_name')->defaultValue('page')->cannotBeEmpty()->info('The default name of the parameter handling the page number.')->end() |
|
84
|
|
|
->scalarNode('enabled_parameter_name')->defaultValue('pagination')->cannotBeEmpty()->info('The name of the query parameter to enable or disable pagination.')->end() |
|
85
|
|
|
->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() |
|
86
|
|
|
->end() |
|
87
|
|
|
->end() |
|
88
|
|
|
->end() |
|
89
|
|
|
->end() |
|
90
|
|
|
->end() |
|
91
|
|
|
; |
|
92
|
|
|
|
|
93
|
|
|
return $treeBuilder; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|