1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
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 Overblog\GraphQLBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
15
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @todo fix xml |
19
|
|
|
*/ |
20
|
|
|
class Configuration implements ConfigurationInterface |
21
|
|
|
{ |
22
|
|
|
private $debug; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Constructor. |
26
|
|
|
* |
27
|
|
|
* @param bool $debug Whether to use the debug mode |
28
|
|
|
*/ |
29
|
36 |
|
public function __construct($debug) |
30
|
|
|
{ |
31
|
36 |
|
$this->debug = (Boolean) $debug; |
32
|
36 |
|
} |
33
|
|
|
|
34
|
36 |
|
public function getConfigTreeBuilder() |
35
|
|
|
{ |
36
|
36 |
|
$treeBuilder = new TreeBuilder(); |
37
|
36 |
|
$rootNode = $treeBuilder->root('overblog_graphql'); |
38
|
|
|
|
39
|
|
|
$rootNode |
40
|
36 |
|
->children() |
41
|
36 |
|
->arrayNode('definitions') |
42
|
36 |
|
->addDefaultsIfNotSet() |
43
|
36 |
|
->children() |
44
|
36 |
|
->scalarNode('internal_error_message')->defaultNull()->end() |
45
|
36 |
|
->booleanNode('config_validation')->defaultValue($this->debug)->end() |
46
|
36 |
|
->arrayNode('schema') |
47
|
36 |
|
->addDefaultsIfNotSet() |
48
|
36 |
|
->children() |
49
|
36 |
|
->scalarNode('query')->defaultNull()->end() |
50
|
36 |
|
->scalarNode('mutation')->defaultNull()->end() |
51
|
36 |
|
->scalarNode('subscription')->defaultNull()->end() |
52
|
36 |
|
->end() |
53
|
36 |
|
->end() |
54
|
36 |
|
->arrayNode('mappings') |
55
|
36 |
|
->children() |
56
|
36 |
|
->arrayNode('types') |
57
|
36 |
|
->prototype('array') |
58
|
36 |
|
->addDefaultsIfNotSet() |
59
|
36 |
|
->children() |
60
|
36 |
|
->enumNode('type')->isRequired()->values(['yml', 'xml'])->end() |
61
|
36 |
|
->scalarNode('dir')->defaultNull()->end() |
62
|
36 |
|
->end() |
63
|
36 |
|
->end() |
64
|
36 |
|
->end() |
65
|
36 |
|
->end() |
66
|
36 |
|
->end() |
67
|
|
|
// TODO remove when types mapping 100% functional |
68
|
36 |
|
->variableNode('types') |
69
|
36 |
|
->info('Defining types using semantic config is deprecated and will be soon removed.') |
70
|
36 |
|
->end() |
71
|
36 |
|
->end() |
72
|
36 |
|
->end() |
73
|
36 |
|
->arrayNode('templates') |
74
|
36 |
|
->addDefaultsIfNotSet() |
75
|
36 |
|
->children() |
76
|
36 |
|
->scalarNode('graphiql') |
77
|
36 |
|
->defaultValue('OverblogGraphQLBundle:GraphiQL:index.html.twig') |
78
|
36 |
|
->end() |
79
|
36 |
|
->end() |
80
|
36 |
|
->end() |
81
|
36 |
|
->arrayNode('services') |
82
|
36 |
|
->addDefaultsIfNotSet() |
83
|
36 |
|
->children() |
84
|
36 |
|
->scalarNode('expression_language') |
85
|
36 |
|
->defaultValue('overblog_graphql.expression_language.default') |
86
|
36 |
|
->end() |
87
|
36 |
|
->scalarNode('cache_expression_language_parser') |
88
|
36 |
|
->defaultValue('overblog_graphql.cache_expression_language_parser.default') |
89
|
36 |
|
->end() |
90
|
36 |
|
->end() |
91
|
36 |
|
->end() |
92
|
36 |
|
->arrayNode('security') |
93
|
36 |
|
->addDefaultsIfNotSet() |
94
|
36 |
|
->children() |
95
|
36 |
|
->integerNode('query_max_depth') |
96
|
36 |
|
->info('Limit query depth. Disabled if equal to false or 0.') |
97
|
36 |
|
->beforeNormalization() |
98
|
|
|
->ifTrue(function ($v) { return false === $v; }) |
99
|
|
|
->then(function () { return 0; }) |
100
|
36 |
|
->end() |
101
|
36 |
|
->defaultFalse() |
102
|
36 |
|
->validate() |
103
|
|
|
->ifTrue(function ($v) { return $v < 0; }) |
104
|
36 |
|
->thenInvalid('Node "overblog_graphql.security.query_max_depth" must be greater or equal to 0.') |
105
|
36 |
|
->end() |
106
|
36 |
|
->end() |
107
|
36 |
|
->end() |
108
|
36 |
|
->end() |
109
|
36 |
|
->end() |
110
|
36 |
|
->end(); |
111
|
|
|
|
112
|
36 |
|
return $treeBuilder; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|