1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
5
|
|
|
* |
6
|
|
|
* (c) Daniel West <[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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
17
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
18
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Daniel West <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class Configuration implements ConfigurationInterface |
24
|
|
|
{ |
25
|
1 |
|
public function getConfigTreeBuilder(): TreeBuilder |
26
|
|
|
{ |
27
|
1 |
|
$treeBuilder = new TreeBuilder('silverback_api_components'); |
28
|
1 |
|
$rootNode = $treeBuilder->getRootNode(); |
29
|
|
|
$rootNode |
30
|
1 |
|
->children() |
31
|
1 |
|
->scalarNode('website_name')->isRequired()->end() |
32
|
1 |
|
->scalarNode('table_prefix')->defaultValue('_acb_')->end() |
33
|
1 |
|
->scalarNode('metadata_key')->defaultValue('_metadata')->end() |
34
|
1 |
|
->end(); |
35
|
|
|
|
36
|
1 |
|
$this->addRouteSecurityNode($rootNode); |
37
|
1 |
|
$this->addRoutableSecurityNode($rootNode); |
38
|
1 |
|
$this->addRefreshTokenNode($rootNode); |
39
|
1 |
|
$this->addPublishableNode($rootNode); |
40
|
1 |
|
$this->addEnabledComponentsNode($rootNode); |
41
|
1 |
|
$this->addUserNode($rootNode); |
42
|
|
|
|
43
|
1 |
|
return $treeBuilder; |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
private function addRouteSecurityNode(ArrayNodeDefinition $rootNode): void |
47
|
|
|
{ |
48
|
|
|
$rootNode |
49
|
1 |
|
->children() |
50
|
1 |
|
->arrayNode('route_security') |
51
|
1 |
|
->arrayPrototype() |
52
|
1 |
|
->children() |
53
|
1 |
|
->scalarNode('route')->end() |
54
|
1 |
|
->scalarNode('security')->end() |
|
|
|
|
55
|
1 |
|
->end() |
56
|
1 |
|
->end() |
57
|
1 |
|
->end() |
58
|
1 |
|
->end(); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
1 |
|
private function addRoutableSecurityNode(ArrayNodeDefinition $rootNode): void |
62
|
|
|
{ |
63
|
|
|
$rootNode |
64
|
1 |
|
->children() |
65
|
1 |
|
->scalarNode('routable_security')->defaultNull()->end() |
66
|
1 |
|
->end(); |
|
|
|
|
67
|
1 |
|
} |
68
|
|
|
|
69
|
1 |
|
private function addRefreshTokenNode(ArrayNodeDefinition $rootNode): void |
70
|
|
|
{ |
71
|
|
|
$rootNode |
72
|
1 |
|
->children() |
73
|
1 |
|
->arrayNode('refresh_token') |
74
|
1 |
|
->addDefaultsIfNotSet() |
75
|
1 |
|
->children() |
76
|
1 |
|
->scalarNode('handler_id')->cannotBeEmpty()->isRequired()->end() |
77
|
1 |
|
->arrayNode('options') |
|
|
|
|
78
|
1 |
|
->useAttributeAsKey('key') |
79
|
1 |
|
->prototype('variable')->end() |
80
|
1 |
|
->end() |
81
|
1 |
|
->scalarNode('cookie_name')->cannotBeEmpty()->isRequired()->end() |
82
|
1 |
|
->scalarNode('ttl')->cannotBeEmpty()->isRequired()->end() |
83
|
1 |
|
->scalarNode('database_user_provider')->cannotBeEmpty()->isRequired()->end() |
84
|
1 |
|
->end() |
85
|
1 |
|
->end() |
86
|
1 |
|
->end(); |
87
|
1 |
|
} |
88
|
|
|
|
89
|
1 |
|
private function addPublishableNode(ArrayNodeDefinition $rootNode): void |
90
|
|
|
{ |
91
|
|
|
$rootNode |
92
|
1 |
|
->children() |
93
|
1 |
|
->arrayNode('publishable') |
94
|
1 |
|
->addDefaultsIfNotSet() |
95
|
1 |
|
->children() |
96
|
1 |
|
->scalarNode('permission')->cannotBeEmpty()->isRequired()->end() |
97
|
1 |
|
->end() |
98
|
1 |
|
->end() |
99
|
1 |
|
->end(); |
100
|
1 |
|
} |
101
|
|
|
|
102
|
1 |
|
private function addEnabledComponentsNode(ArrayNodeDefinition $rootNode): void |
103
|
|
|
{ |
104
|
|
|
$rootNode |
105
|
1 |
|
->children() |
106
|
1 |
|
->arrayNode('enabled_components') |
107
|
1 |
|
->addDefaultsIfNotSet() |
108
|
1 |
|
->children() |
109
|
1 |
|
->booleanNode('form')->defaultValue(true)->end() |
110
|
1 |
|
->booleanNode('collection')->defaultValue(true)->end() |
|
|
|
|
111
|
1 |
|
->end() |
112
|
1 |
|
->end() |
113
|
1 |
|
->end(); |
114
|
1 |
|
} |
115
|
|
|
|
116
|
1 |
|
private function addUserNode(ArrayNodeDefinition $rootNode): void |
117
|
|
|
{ |
118
|
|
|
$rootNode |
119
|
1 |
|
->children() |
120
|
1 |
|
->arrayNode('user') |
121
|
1 |
|
->addDefaultsIfNotSet() |
122
|
1 |
|
->children() |
123
|
1 |
|
->scalarNode('class_name') |
124
|
1 |
|
->isRequired() |
125
|
1 |
|
->end() |
126
|
1 |
|
->arrayNode('email_verification') |
127
|
1 |
|
->canBeDisabled() |
128
|
1 |
|
->addDefaultsIfNotSet() |
129
|
1 |
|
->children() |
130
|
1 |
|
->arrayNode('email') |
131
|
1 |
|
->children() |
132
|
1 |
|
->scalarNode('redirect_path_query')->end() |
133
|
1 |
|
->scalarNode('default_redirect_path')->isRequired()->end() |
134
|
1 |
|
->scalarNode('subject')->cannotBeEmpty()->defaultValue('Please verify your email')->end() |
135
|
1 |
|
->end() |
136
|
1 |
|
->end() |
137
|
1 |
|
->booleanNode('default_value')->isRequired()->end() |
138
|
1 |
|
->booleanNode('verify_on_change')->isRequired()->end() |
139
|
1 |
|
->booleanNode('verify_on_register')->isRequired()->end() |
140
|
1 |
|
->booleanNode('deny_unverified_login')->isRequired()->end() |
141
|
1 |
|
->end() |
142
|
1 |
|
->end() |
143
|
1 |
|
->arrayNode('new_email_confirmation') |
144
|
1 |
|
->addDefaultsIfNotSet() |
145
|
1 |
|
->children() |
146
|
1 |
|
->arrayNode('email') |
147
|
1 |
|
->children() |
148
|
1 |
|
->scalarNode('redirect_path_query')->end() |
149
|
1 |
|
->scalarNode('default_redirect_path')->isRequired()->end() |
150
|
1 |
|
->scalarNode('subject')->cannotBeEmpty()->defaultValue('Please confirm your new email address')->end() |
151
|
1 |
|
->end() |
152
|
1 |
|
->end() |
153
|
1 |
|
->integerNode('request_timeout_seconds')->defaultValue(86400)->end() |
154
|
1 |
|
->end() |
155
|
1 |
|
->end() |
156
|
1 |
|
->arrayNode('password_reset') |
157
|
1 |
|
->addDefaultsIfNotSet() |
158
|
1 |
|
->children() |
159
|
1 |
|
->arrayNode('email') |
160
|
1 |
|
->children() |
161
|
1 |
|
->scalarNode('redirect_path_query')->end() |
162
|
1 |
|
->scalarNode('default_redirect_path')->isRequired()->end() |
163
|
1 |
|
->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your password has been reset')->end() |
164
|
1 |
|
->end() |
165
|
1 |
|
->end() |
166
|
1 |
|
->integerNode('repeat_ttl_seconds')->defaultValue(8600)->end() |
167
|
1 |
|
->integerNode('request_timeout_seconds')->defaultValue(3600)->end() |
168
|
1 |
|
->end() |
169
|
1 |
|
->end() |
170
|
1 |
|
->arrayNode('emails') |
171
|
1 |
|
->addDefaultsIfNotSet() |
172
|
1 |
|
->children() |
173
|
1 |
|
->arrayNode('welcome') |
174
|
1 |
|
->canBeDisabled() |
175
|
1 |
|
->addDefaultsIfNotSet() |
176
|
1 |
|
->children() |
177
|
1 |
|
->scalarNode('subject')->cannotBeEmpty()->defaultValue('Welcome to {{ website_name }}')->end() |
178
|
1 |
|
->end() |
179
|
1 |
|
->end() |
180
|
1 |
|
->arrayNode('user_enabled') |
181
|
1 |
|
->canBeDisabled() |
182
|
1 |
|
->addDefaultsIfNotSet() |
183
|
1 |
|
->children() |
184
|
1 |
|
->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your account has been enabled')->end() |
185
|
1 |
|
->end() |
186
|
1 |
|
->end() |
187
|
1 |
|
->arrayNode('username_changed') |
188
|
1 |
|
->canBeDisabled() |
189
|
1 |
|
->addDefaultsIfNotSet() |
190
|
1 |
|
->children() |
191
|
1 |
|
->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your username has been updated')->end() |
192
|
1 |
|
->end() |
193
|
1 |
|
->end() |
194
|
1 |
|
->arrayNode('password_changed') |
195
|
1 |
|
->canBeDisabled() |
196
|
1 |
|
->addDefaultsIfNotSet() |
197
|
1 |
|
->children() |
198
|
1 |
|
->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your password has been changed')->end() |
199
|
1 |
|
->end() |
200
|
1 |
|
->end() |
201
|
1 |
|
->end() |
202
|
1 |
|
->end() |
203
|
1 |
|
->end() |
204
|
1 |
|
->end() |
205
|
1 |
|
->end(); |
206
|
1 |
|
} |
207
|
|
|
} |
208
|
|
|
|