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