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