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