]> Raphaël G. Git Repositories - userbundle/blob - DependencyInjection/Configuration.php
Transform default scalar prototype in variable prototype to allow custom defaults
[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 'civility' => 'Mister',
43 'group' => [ 'User' ]
44 ],
45 'route' => [
46 'confirm' => [
47 'name' => 'rapsys_user_confirm',
48 'context' => []
49 ],
50 'edit' => [
51 'name' => 'rapsys_user_edit',
52 'context' => []
53 ],
54 'index' => [
55 'name' => 'rapsys_user_index',
56 'context' => []
57 ],
58 'login' => [
59 'name' => 'rapsys_user_login',
60 'context' => []
61 ],
62 'recover' => [
63 'name' => 'rapsys_user_recover',
64 'context' => []
65 ],
66 'register' => [
67 'name' => 'rapsys_user_register',
68 'context' => []
69 ]
70 ],
71 'translate' => [],
72 'locales' => '%kernel.translator.fallbacks%',
73 'languages' => [
74 'en_gb' => 'English'
75 ],
76 'contact' => [
77 'title' => 'John Doe',
78 'mail' => 'contact@example.com'
79 ],
80 'context' => [],
81 'edit' => [
82 'field' => [],
83 'route' => ['index' => 'index_url'],
84 'view' => [
85 'name' => '@RapsysUser/form/register.html.twig',
86 'edit' => 'Rapsys\UserBundle\Form\RegisterType',
87 'reset' => 'Rapsys\UserBundle\Form\LoginType',
88 'context' => []
89 ]
90 ],
91 'login' => [
92 'route' => ['index' => 'index_url'],
93 'view' => [
94 'name' => '@RapsysUser/form/login.html.twig',
95 'form' => 'Rapsys\UserBundle\Form\LoginType',
96 'context' => []
97 ]
98 ],
99 'recover' => [
100 'route' => ['index' => 'index_url', 'recover' => 'recover_url'],
101 'view' => [
102 'name' => '@RapsysUser/form/recover.html.twig',
103 'form' => 'Rapsys\UserBundle\Form\LoginType',
104 'context' => []
105 ],
106 'mail' => [
107 'subject' => 'Welcome back!',
108 'html' => '@RapsysUser/mail/recover.html.twig',
109 'text' => '@RapsysUser/mail/recover.text.twig',
110 'context' => []
111 ]
112 ],
113 'register' => [
114 'field' => [],
115 'route' => ['index' => 'index_url', 'confirm' => 'confirm_url'],
116 'view' => [
117 'name' => '@RapsysUser/form/register.html.twig',
118 'form' => 'Rapsys\UserBundle\Form\RegisterType',
119 'context' => []
120 ],
121 'mail' => [
122 'subject' => 'Welcome!',
123 'html' => '@RapsysUser/mail/register.html.twig',
124 'text' => '@RapsysUser/mail/register.text.twig',
125 'context' => []
126 ]
127 ]
128 ];
129
130 /**
131 * Defines parameters allowed to configure the bundle
132 *
133 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
134 * @link http://symfony.com/doc/current/components/config/definition.html
135 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
136 *
137 * @see php bin/console config:dump-reference rapsys_user to dump default config
138 * @see php bin/console debug:config rapsys_user to dump config
139 */
140 $treeBuilder
141 //Parameters
142 ->getRootNode()
143 ->addDefaultsIfNotSet()
144 ->children()
145 ->arrayNode('class')
146 ->treatNullLike([])
147 ->defaultValue($defaults['class'])
148 ->scalarPrototype()->end()
149 ->end()
150 ->arrayNode('default')
151 ->treatNullLike([])
152 ->defaultValue($defaults['default'])
153 ->variablePrototype()->end()
154 ->end()
155 ->arrayNode('route')
156 ->addDefaultsIfNotSet()
157 ->children()
158 ->arrayNode('confirm')
159 ->addDefaultsIfNotSet()
160 ->children()
161 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['confirm']['name'])->end()
162 ->arrayNode('context')
163 ->treatNullLike([])
164 ->defaultValue($defaults['route']['confirm']['context'])
165 ->scalarPrototype()->end()
166 ->end()
167 ->end()
168 ->end()
169 ->arrayNode('index')
170 ->addDefaultsIfNotSet()
171 ->children()
172 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['index']['name'])->end()
173 ->arrayNode('context')
174 ->treatNullLike([])
175 ->defaultValue($defaults['route']['index']['context'])
176 ->scalarPrototype()->end()
177 ->end()
178 ->end()
179 ->end()
180 ->arrayNode('edit')
181 ->addDefaultsIfNotSet()
182 ->children()
183 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['edit']['name'])->end()
184 ->arrayNode('context')
185 ->treatNullLike([])
186 ->defaultValue($defaults['route']['edit']['context'])
187 ->scalarPrototype()->end()
188 ->end()
189 ->end()
190 ->end()
191 ->arrayNode('login')
192 ->addDefaultsIfNotSet()
193 ->children()
194 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['login']['name'])->end()
195 ->arrayNode('context')
196 ->treatNullLike([])
197 ->defaultValue($defaults['route']['login']['context'])
198 ->scalarPrototype()->end()
199 ->end()
200 ->end()
201 ->end()
202 ->arrayNode('recover')
203 ->addDefaultsIfNotSet()
204 ->children()
205 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['recover']['name'])->end()
206 ->arrayNode('context')
207 ->treatNullLike([])
208 ->defaultValue($defaults['route']['recover']['context'])
209 ->scalarPrototype()->end()
210 ->end()
211 ->end()
212 ->end()
213 ->arrayNode('register')
214 ->addDefaultsIfNotSet()
215 ->children()
216 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['register']['name'])->end()
217 ->arrayNode('context')
218 ->treatNullLike([])
219 ->defaultValue($defaults['route']['register']['context'])
220 ->scalarPrototype()->end()
221 ->end()
222 ->end()
223 ->end()
224 ->end()
225 ->end()
226 ->arrayNode('translate')
227 ->treatNullLike([])
228 ->defaultValue($defaults['translate'])
229 ->scalarPrototype()->end()
230 ->end()
231 ->scalarNode('locales')->cannotBeEmpty()->defaultValue($defaults['locales'])->end()
232 ->arrayNode('languages')
233 ->treatNullLike([])
234 ->defaultValue($defaults['languages'])
235 ->scalarPrototype()->end()
236 ->end()
237 ->arrayNode('contact')
238 ->addDefaultsIfNotSet()
239 ->children()
240 ->scalarNode('title')->cannotBeEmpty()->defaultValue($defaults['contact']['title'])->end()
241 ->scalarNode('mail')->cannotBeEmpty()->defaultValue($defaults['contact']['mail'])->end()
242 ->end()
243 ->end()
244 ->arrayNode('context')
245 ->treatNullLike([])
246 ->defaultValue($defaults['context'])
247 ->variablePrototype()->end()
248 ->end()
249 ->arrayNode('edit')
250 ->addDefaultsIfNotSet()
251 ->children()
252 ->arrayNode('field')
253 ->treatNullLike([])
254 ->defaultValue($defaults['edit']['field'])
255 ->variablePrototype()->end()
256 ->end()
257 ->arrayNode('route')
258 ->treatNullLike([])
259 ->defaultValue($defaults['edit']['route'])
260 ->scalarPrototype()->end()
261 ->end()
262 ->arrayNode('view')
263 ->addDefaultsIfNotSet()
264 ->children()
265 ->scalarNode('edit')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['edit'])->end()
266 ->scalarNode('reset')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['reset'])->end()
267 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['name'])->end()
268 ->arrayNode('context')
269 ->treatNullLike([])
270 ->defaultValue($defaults['edit']['view']['context'])
271 ->variablePrototype()->end()
272 ->end()
273 ->end()
274 ->end()
275 ->end()
276 ->end()
277 ->arrayNode('login')
278 ->addDefaultsIfNotSet()
279 ->children()
280 ->arrayNode('route')
281 ->treatNullLike([])
282 ->defaultValue($defaults['login']['route'])
283 ->scalarPrototype()->end()
284 ->end()
285 ->arrayNode('view')
286 ->addDefaultsIfNotSet()
287 ->children()
288 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['login']['view']['name'])->end()
289 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['login']['view']['form'])->end()
290 ->arrayNode('context')
291 ->treatNullLike([])
292 ->defaultValue($defaults['login']['view']['context'])
293 ->variablePrototype()->end()
294 ->end()
295 ->end()
296 ->end()
297 ->end()
298 ->end()
299 ->arrayNode('recover')
300 ->addDefaultsIfNotSet()
301 ->children()
302 ->arrayNode('route')
303 ->treatNullLike([])
304 ->defaultValue($defaults['recover']['route'])
305 ->scalarPrototype()->end()
306 ->end()
307 ->arrayNode('view')
308 ->addDefaultsIfNotSet()
309 ->children()
310 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['recover']['view']['name'])->end()
311 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['recover']['view']['form'])->end()
312 ->arrayNode('context')
313 ->treatNullLike([])
314 ->defaultValue($defaults['recover']['view']['context'])
315 ->variablePrototype()->end()
316 ->end()
317 ->end()
318 ->end()
319 ->arrayNode('mail')
320 ->addDefaultsIfNotSet()
321 ->children()
322 ->scalarNode('subject')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['subject'])->end()
323 ->scalarNode('html')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['html'])->end()
324 ->scalarNode('text')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['text'])->end()
325 ->arrayNode('context')
326 ->treatNullLike([])
327 ->defaultValue($defaults['recover']['mail']['context'])
328 ->variablePrototype()->end()
329 ->end()
330 ->end()
331 ->end()
332 ->end()
333 ->end()
334 ->arrayNode('register')
335 ->addDefaultsIfNotSet()
336 ->children()
337 ->arrayNode('field')
338 ->treatNullLike([])
339 ->defaultValue($defaults['register']['field'])
340 ->variablePrototype()->end()
341 ->end()
342 ->arrayNode('route')
343 ->treatNullLike([])
344 ->defaultValue($defaults['register']['route'])
345 ->scalarPrototype()->end()
346 ->end()
347 ->arrayNode('view')
348 ->addDefaultsIfNotSet()
349 ->children()
350 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['register']['view']['form'])->end()
351 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['register']['view']['name'])->end()
352 ->arrayNode('context')
353 ->treatNullLike([])
354 ->defaultValue($defaults['register']['view']['context'])
355 ->variablePrototype()->end()
356 ->end()
357 ->end()
358 ->end()
359 ->arrayNode('mail')
360 ->addDefaultsIfNotSet()
361 ->children()
362 ->scalarNode('subject')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['subject'])->end()
363 ->scalarNode('html')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['html'])->end()
364 ->scalarNode('text')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['text'])->end()
365 ->arrayNode('context')
366 ->treatNullLike([])
367 ->defaultValue($defaults['register']['mail']['context'])
368 ->variablePrototype()->end()
369 ->end()
370 ->end()
371 ->end()
372 ->end()
373 ->end()
374 ->end()
375 ->end();
376
377 return $treeBuilder;
378 }
379 }