]> Raphaël G. Git Repositories - userbundle/blob - DependencyInjection/Configuration.php
Replace findAllAsArray with findIndexByGroupId
[userbundle] / DependencyInjection / Configuration.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys UserBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
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 Rapsys\UserBundle\DependencyInjection;
13
14 use Rapsys\UserBundle\RapsysUserBundle;
15
16 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17 use Symfony\Component\Config\Definition\ConfigurationInterface;
18
19 /**
20 * {@inheritdoc}
21 *
22 * This is the class that validates and merges configuration from your app/config files.
23 *
24 * @link http://symfony.com/doc/current/cookbook/bundles/configuration.html
25 */
26 class Configuration implements ConfigurationInterface {
27 /**
28 * {@inheritdoc}
29 */
30 public function getConfigTreeBuilder(): TreeBuilder {
31 //Set tree builder
32 $treeBuilder = new TreeBuilder(RapsysUserBundle::getAlias());
33
34 //The bundle default values
35 $defaults = [
36 'class' => [
37 'civility' => 'Rapsys\\UserBundle\\Entity\\Civility',
38 'group' => 'Rapsys\\UserBundle\\Entity\\Group',
39 'user' => 'Rapsys\\UserBundle\\Entity\\User'
40 ],
41 'default' => [
42 'admin' => 'ROLE_ADMIN',
43 'civility' => 'Mister',
44 'languages' => [
45 'en_gb' => 'English'
46 ],
47 'locales' => [ 'en_gb' ],
48 'group' => [ 'User' ]
49 ],
50 'route' => [
51 'confirm' => [
52 'name' => 'rapsysuser_confirm',
53 'context' => []
54 ],
55 'edit' => [
56 'name' => 'rapsysuser_edit',
57 'context' => []
58 ],
59 'index' => [
60 'name' => 'rapsysuser_index',
61 'context' => []
62 ],
63 'login' => [
64 'name' => 'rapsysuser_login',
65 'context' => []
66 ],
67 'recover' => [
68 'name' => 'rapsysuser_recover',
69 'context' => []
70 ],
71 'register' => [
72 'name' => 'rapsysuser_register',
73 'context' => []
74 ]
75 ],
76 'translate' => [],
77 'contact' => [
78 'address' => 'contact@example.com',
79 'name' => 'John Doe'
80 ],
81 'context' => [],
82 'edit' => [
83 'admin' => ['mail' => true, 'pseudonym' => true],
84 'field' => [],
85 'route' => ['index' => 'index_url'],
86 'view' => [
87 'name' => '@RapsysUser/form/register.html.twig',
88 'edit' => 'Rapsys\UserBundle\Form\EditType',
89 'reset' => 'Rapsys\UserBundle\Form\ResetType',
90 'context' => []
91 ]
92 ],
93 'index' => [
94 'route' => ['index' => 'index_url'],
95 'view' => [
96 'name' => '@RapsysUser/form/index.html.twig',
97 'context' => []
98 ]
99 ],
100 'login' => [
101 'route' => ['index' => 'index_url'],
102 'view' => [
103 'name' => '@RapsysUser/form/login.html.twig',
104 'form' => 'Rapsys\UserBundle\Form\LoginType',
105 'context' => []
106 ]
107 ],
108 'recover' => [
109 'route' => ['index' => 'index_url', 'recover' => 'recover_url'],
110 'view' => [
111 'name' => '@RapsysUser/form/recover.html.twig',
112 'form' => 'Rapsys\UserBundle\Form\RecoverType',
113 'context' => []
114 ],
115 'mail' => [
116 'subject' => 'Welcome back!',
117 'html' => '@RapsysUser/mail/recover.html.twig',
118 'text' => '@RapsysUser/mail/recover.text.twig',
119 'context' => []
120 ]
121 ],
122 'register' => [
123 'admin' => [],
124 'field' => [],
125 'route' => ['index' => 'index_url', 'confirm' => 'confirm_url'],
126 'view' => [
127 'name' => '@RapsysUser/form/register.html.twig',
128 'form' => 'Rapsys\UserBundle\Form\RegisterType',
129 'context' => []
130 ],
131 'mail' => [
132 'subject' => 'Welcome!',
133 'html' => '@RapsysUser/mail/register.html.twig',
134 'text' => '@RapsysUser/mail/register.text.twig',
135 'context' => []
136 ]
137 ]
138 ];
139
140 /**
141 * Defines parameters allowed to configure the bundle
142 *
143 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
144 * @link http://symfony.com/doc/current/components/config/definition.html
145 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
146 *
147 * @see php bin/console config:dump-reference rapsysuser to dump default config
148 * @see php bin/console debug:config rapsysuser to dump config
149 */
150 $treeBuilder
151 //Parameters
152 ->getRootNode()
153 ->addDefaultsIfNotSet()
154 ->children()
155 ->arrayNode('class')
156 ->addDefaultsIfNotSet()
157 #XXX: ignoreExtraKeys(bool $remove = true)
158 ->ignoreExtraKeys(false)
159 ->children()
160 ->scalarNode('civility')->cannotBeEmpty()->defaultValue($defaults['class']['civility'])->end()
161 ->scalarNode('group')->cannotBeEmpty()->defaultValue($defaults['class']['group'])->end()
162 ->scalarNode('user')->cannotBeEmpty()->defaultValue($defaults['class']['user'])->end()
163 ->end()
164 ->end()
165 ->arrayNode('default')
166 ->addDefaultsIfNotSet()
167 #XXX: ignoreExtraKeys(bool $remove = true)
168 ->ignoreExtraKeys(false)
169 ->children()
170 ->scalarNode('admin')->cannotBeEmpty()->defaultValue($defaults['default']['admin'])->end()
171 ->scalarNode('civility')->cannotBeEmpty()->defaultValue($defaults['default']['civility'])->end()
172 #TODO: see if we can't prevent key normalisation with ->normalizeKeys(false)
173 ->arrayNode('languages')
174 ->treatNullLike([])
175 ->defaultValue($defaults['default']['languages'])
176 ->scalarPrototype()->end()
177 ->end()
178 #TODO: see if we can't prevent key normalisation with ->normalizeKeys(false)
179 ->arrayNode('locales')
180 ->treatNullLike([])
181 ->defaultValue($defaults['default']['locales'])
182 ->scalarPrototype()->end()
183 ->end()
184 ->arrayNode('group')
185 ->treatNullLike([])
186 ->defaultValue($defaults['default']['group'])
187 ->scalarPrototype()->end()
188 ->end()
189 ->end()
190 ->end()
191 ->arrayNode('route')
192 ->addDefaultsIfNotSet()
193 ->children()
194 ->arrayNode('confirm')
195 ->addDefaultsIfNotSet()
196 ->children()
197 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['confirm']['name'])->end()
198 ->arrayNode('context')
199 ->treatNullLike([])
200 ->defaultValue($defaults['route']['confirm']['context'])
201 ->scalarPrototype()->end()
202 ->end()
203 ->end()
204 ->end()
205 ->arrayNode('index')
206 ->addDefaultsIfNotSet()
207 ->children()
208 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['index']['name'])->end()
209 ->arrayNode('context')
210 ->treatNullLike([])
211 ->defaultValue($defaults['route']['index']['context'])
212 ->scalarPrototype()->end()
213 ->end()
214 ->end()
215 ->end()
216 ->arrayNode('edit')
217 ->addDefaultsIfNotSet()
218 ->children()
219 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['edit']['name'])->end()
220 ->arrayNode('context')
221 ->treatNullLike([])
222 ->defaultValue($defaults['route']['edit']['context'])
223 ->scalarPrototype()->end()
224 ->end()
225 ->end()
226 ->end()
227 ->arrayNode('login')
228 ->addDefaultsIfNotSet()
229 ->children()
230 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['login']['name'])->end()
231 ->arrayNode('context')
232 ->treatNullLike([])
233 ->defaultValue($defaults['route']['login']['context'])
234 ->scalarPrototype()->end()
235 ->end()
236 ->end()
237 ->end()
238 ->arrayNode('recover')
239 ->addDefaultsIfNotSet()
240 ->children()
241 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['recover']['name'])->end()
242 ->arrayNode('context')
243 ->treatNullLike([])
244 ->defaultValue($defaults['route']['recover']['context'])
245 ->scalarPrototype()->end()
246 ->end()
247 ->end()
248 ->end()
249 ->arrayNode('register')
250 ->addDefaultsIfNotSet()
251 ->children()
252 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['register']['name'])->end()
253 ->arrayNode('context')
254 ->treatNullLike([])
255 ->defaultValue($defaults['route']['register']['context'])
256 ->scalarPrototype()->end()
257 ->end()
258 ->end()
259 ->end()
260 ->end()
261 ->end()
262 ->arrayNode('translate')
263 ->treatNullLike([])
264 ->defaultValue($defaults['translate'])
265 ->scalarPrototype()->end()
266 ->end()
267 ->arrayNode('contact')
268 ->addDefaultsIfNotSet()
269 ->children()
270 ->scalarNode('address')->cannotBeEmpty()->defaultValue($defaults['contact']['address'])->end()
271 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['contact']['name'])->end()
272 ->end()
273 ->end()
274 ->arrayNode('context')
275 ->treatNullLike([])
276 ->defaultValue($defaults['context'])
277 ->variablePrototype()->end()
278 ->end()
279 ->arrayNode('edit')
280 ->addDefaultsIfNotSet()
281 ->children()
282 ->arrayNode('admin')
283 ->treatNullLike([])
284 ->defaultValue($defaults['edit']['admin'])
285 ->variablePrototype()->end()
286 ->end()
287 ->arrayNode('field')
288 ->treatNullLike([])
289 ->defaultValue($defaults['edit']['field'])
290 ->variablePrototype()->end()
291 ->end()
292 ->arrayNode('route')
293 ->treatNullLike([])
294 ->defaultValue($defaults['edit']['route'])
295 ->scalarPrototype()->end()
296 ->end()
297 ->arrayNode('view')
298 ->addDefaultsIfNotSet()
299 ->children()
300 ->scalarNode('edit')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['edit'])->end()
301 ->scalarNode('reset')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['reset'])->end()
302 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['name'])->end()
303 ->arrayNode('context')
304 ->treatNullLike([])
305 ->defaultValue($defaults['edit']['view']['context'])
306 ->variablePrototype()->end()
307 ->end()
308 ->end()
309 ->end()
310 ->end()
311 ->end()
312 ->arrayNode('index')
313 ->addDefaultsIfNotSet()
314 ->children()
315 ->arrayNode('route')
316 ->treatNullLike([])
317 ->defaultValue($defaults['index']['route'])
318 ->scalarPrototype()->end()
319 ->end()
320 ->arrayNode('view')
321 ->addDefaultsIfNotSet()
322 ->children()
323 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['index']['view']['name'])->end()
324 ->arrayNode('context')
325 ->treatNullLike([])
326 ->defaultValue($defaults['index']['view']['context'])
327 ->variablePrototype()->end()
328 ->end()
329 ->end()
330 ->end()
331 ->end()
332 ->end()
333 ->arrayNode('login')
334 ->addDefaultsIfNotSet()
335 ->children()
336 ->arrayNode('route')
337 ->treatNullLike([])
338 ->defaultValue($defaults['login']['route'])
339 ->scalarPrototype()->end()
340 ->end()
341 ->arrayNode('view')
342 ->addDefaultsIfNotSet()
343 ->children()
344 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['login']['view']['name'])->end()
345 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['login']['view']['form'])->end()
346 ->arrayNode('context')
347 ->treatNullLike([])
348 ->defaultValue($defaults['login']['view']['context'])
349 ->variablePrototype()->end()
350 ->end()
351 ->end()
352 ->end()
353 ->end()
354 ->end()
355 ->arrayNode('recover')
356 ->addDefaultsIfNotSet()
357 ->children()
358 ->arrayNode('route')
359 ->treatNullLike([])
360 ->defaultValue($defaults['recover']['route'])
361 ->scalarPrototype()->end()
362 ->end()
363 ->arrayNode('view')
364 ->addDefaultsIfNotSet()
365 ->children()
366 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['recover']['view']['name'])->end()
367 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['recover']['view']['form'])->end()
368 ->arrayNode('context')
369 ->treatNullLike([])
370 ->defaultValue($defaults['recover']['view']['context'])
371 ->variablePrototype()->end()
372 ->end()
373 ->end()
374 ->end()
375 ->arrayNode('mail')
376 ->addDefaultsIfNotSet()
377 ->children()
378 ->scalarNode('subject')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['subject'])->end()
379 ->scalarNode('html')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['html'])->end()
380 ->scalarNode('text')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['text'])->end()
381 ->arrayNode('context')
382 ->treatNullLike([])
383 ->defaultValue($defaults['recover']['mail']['context'])
384 ->variablePrototype()->end()
385 ->end()
386 ->end()
387 ->end()
388 ->end()
389 ->end()
390 ->arrayNode('register')
391 ->addDefaultsIfNotSet()
392 ->children()
393 ->arrayNode('admin')
394 ->treatNullLike([])
395 ->defaultValue($defaults['edit']['admin'])
396 ->variablePrototype()->end()
397 ->end()
398 ->arrayNode('field')
399 ->treatNullLike([])
400 ->defaultValue($defaults['register']['field'])
401 ->variablePrototype()->end()
402 ->end()
403 ->arrayNode('route')
404 ->treatNullLike([])
405 ->defaultValue($defaults['register']['route'])
406 ->scalarPrototype()->end()
407 ->end()
408 ->arrayNode('view')
409 ->addDefaultsIfNotSet()
410 ->children()
411 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['register']['view']['form'])->end()
412 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['register']['view']['name'])->end()
413 ->arrayNode('context')
414 ->treatNullLike([])
415 ->defaultValue($defaults['register']['view']['context'])
416 ->variablePrototype()->end()
417 ->end()
418 ->end()
419 ->end()
420 ->arrayNode('mail')
421 ->addDefaultsIfNotSet()
422 ->children()
423 ->scalarNode('subject')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['subject'])->end()
424 ->scalarNode('html')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['html'])->end()
425 ->scalarNode('text')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['text'])->end()
426 ->arrayNode('context')
427 ->treatNullLike([])
428 ->defaultValue($defaults['register']['mail']['context'])
429 ->variablePrototype()->end()
430 ->end()
431 ->end()
432 ->end()
433 ->end()
434 ->end()
435 ->end()
436 ->end();
437
438 return $treeBuilder;
439 }
440 }