]> Raphaël G. Git Repositories - userbundle/blob - DependencyInjection/Configuration.php
Add contribute
[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 #TODO: see if we can't prevent key normalisation with ->normalizeKeys(false)
232 ->scalarNode('locales')->cannotBeEmpty()->defaultValue($defaults['locales'])->end()
233 #TODO: see if we can't prevent key normalisation with ->normalizeKeys(false)
234 ->arrayNode('languages')
235 ->treatNullLike([])
236 ->defaultValue($defaults['languages'])
237 ->scalarPrototype()->end()
238 ->end()
239 ->arrayNode('contact')
240 ->addDefaultsIfNotSet()
241 ->children()
242 ->scalarNode('title')->cannotBeEmpty()->defaultValue($defaults['contact']['title'])->end()
243 ->scalarNode('mail')->cannotBeEmpty()->defaultValue($defaults['contact']['mail'])->end()
244 ->end()
245 ->end()
246 ->arrayNode('context')
247 ->treatNullLike([])
248 ->defaultValue($defaults['context'])
249 ->variablePrototype()->end()
250 ->end()
251 ->arrayNode('edit')
252 ->addDefaultsIfNotSet()
253 ->children()
254 ->arrayNode('field')
255 ->treatNullLike([])
256 ->defaultValue($defaults['edit']['field'])
257 ->variablePrototype()->end()
258 ->end()
259 ->arrayNode('route')
260 ->treatNullLike([])
261 ->defaultValue($defaults['edit']['route'])
262 ->scalarPrototype()->end()
263 ->end()
264 ->arrayNode('view')
265 ->addDefaultsIfNotSet()
266 ->children()
267 ->scalarNode('edit')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['edit'])->end()
268 ->scalarNode('reset')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['reset'])->end()
269 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['name'])->end()
270 ->arrayNode('context')
271 ->treatNullLike([])
272 ->defaultValue($defaults['edit']['view']['context'])
273 ->variablePrototype()->end()
274 ->end()
275 ->end()
276 ->end()
277 ->end()
278 ->end()
279 ->arrayNode('login')
280 ->addDefaultsIfNotSet()
281 ->children()
282 ->arrayNode('route')
283 ->treatNullLike([])
284 ->defaultValue($defaults['login']['route'])
285 ->scalarPrototype()->end()
286 ->end()
287 ->arrayNode('view')
288 ->addDefaultsIfNotSet()
289 ->children()
290 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['login']['view']['name'])->end()
291 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['login']['view']['form'])->end()
292 ->arrayNode('context')
293 ->treatNullLike([])
294 ->defaultValue($defaults['login']['view']['context'])
295 ->variablePrototype()->end()
296 ->end()
297 ->end()
298 ->end()
299 ->end()
300 ->end()
301 ->arrayNode('recover')
302 ->addDefaultsIfNotSet()
303 ->children()
304 ->arrayNode('route')
305 ->treatNullLike([])
306 ->defaultValue($defaults['recover']['route'])
307 ->scalarPrototype()->end()
308 ->end()
309 ->arrayNode('view')
310 ->addDefaultsIfNotSet()
311 ->children()
312 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['recover']['view']['name'])->end()
313 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['recover']['view']['form'])->end()
314 ->arrayNode('context')
315 ->treatNullLike([])
316 ->defaultValue($defaults['recover']['view']['context'])
317 ->variablePrototype()->end()
318 ->end()
319 ->end()
320 ->end()
321 ->arrayNode('mail')
322 ->addDefaultsIfNotSet()
323 ->children()
324 ->scalarNode('subject')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['subject'])->end()
325 ->scalarNode('html')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['html'])->end()
326 ->scalarNode('text')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['text'])->end()
327 ->arrayNode('context')
328 ->treatNullLike([])
329 ->defaultValue($defaults['recover']['mail']['context'])
330 ->variablePrototype()->end()
331 ->end()
332 ->end()
333 ->end()
334 ->end()
335 ->end()
336 ->arrayNode('register')
337 ->addDefaultsIfNotSet()
338 ->children()
339 ->arrayNode('field')
340 ->treatNullLike([])
341 ->defaultValue($defaults['register']['field'])
342 ->variablePrototype()->end()
343 ->end()
344 ->arrayNode('route')
345 ->treatNullLike([])
346 ->defaultValue($defaults['register']['route'])
347 ->scalarPrototype()->end()
348 ->end()
349 ->arrayNode('view')
350 ->addDefaultsIfNotSet()
351 ->children()
352 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['register']['view']['form'])->end()
353 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['register']['view']['name'])->end()
354 ->arrayNode('context')
355 ->treatNullLike([])
356 ->defaultValue($defaults['register']['view']['context'])
357 ->variablePrototype()->end()
358 ->end()
359 ->end()
360 ->end()
361 ->arrayNode('mail')
362 ->addDefaultsIfNotSet()
363 ->children()
364 ->scalarNode('subject')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['subject'])->end()
365 ->scalarNode('html')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['html'])->end()
366 ->scalarNode('text')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['text'])->end()
367 ->arrayNode('context')
368 ->treatNullLike([])
369 ->defaultValue($defaults['register']['mail']['context'])
370 ->variablePrototype()->end()
371 ->end()
372 ->end()
373 ->end()
374 ->end()
375 ->end()
376 ->end()
377 ->end();
378
379 return $treeBuilder;
380 }
381 }