]> Raphaël G. Git Repositories - userbundle/blob - DependencyInjection/RapsysUserExtension.php
Set rapsysuser.default.{admin,group} keys
[userbundle] / DependencyInjection / RapsysUserExtension.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\DependencyInjection\ContainerBuilder;
17 use Symfony\Component\DependencyInjection\Extension\Extension;
18
19 /**
20 * This is the class that loads and manages your bundle configuration.
21 *
22 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
23 */
24 class RapsysUserExtension extends Extension {
25 /**
26 * {@inheritdoc}
27 */
28 public function load(array $configs, ContainerBuilder $container): void {
29 //Load configuration
30 $configuration = $this->getConfiguration($configs, $container);
31
32 //Process the configuration to get merged config
33 $config = $this->processConfiguration($configuration, $configs);
34
35 //Set bundle alias
36 $alias = RapsysUserBundle::getAlias();
37
38 //Detect when no user configuration is provided
39 if ($configs === [[]]) {
40 //Prepend default config
41 $container->prependExtensionConfig($alias, $config);
42 }
43
44 //Save configuration in parameters
45 $container->setParameter($alias, $config);
46
47 //Set rapsysuser.default.admin key
48 $container->setParameter($alias.'.default.admin', $config['default']['admin']);
49
50 //Set rapsysuser.default.group key
51 $container->setParameter($alias.'.default.group', $config['default']['group']);
52
53 //Set rapsysuser.alias key
54 $container->setParameter($alias.'.alias', $alias);
55
56 //Set rapsysuser.version key
57 $container->setParameter($alias.'.version', RapsysUserBundle::getVersion());
58 }
59
60 /**
61 * {@inheritdoc}
62 *
63 * @xxx Required by kernel to load renamed alias configuration
64 */
65 public function getAlias(): string {
66 return RapsysUserBundle::getAlias();
67 }
68 }