]> Raphaƫl G. Git Repositories - userbundle/blob - DependencyInjection/RapsysUserExtension.php
58c86a60321f6539928655574416a48a2da4a295
[userbundle] / DependencyInjection / RapsysUserExtension.php
1 <?php
2
3 namespace Rapsys\UserBundle\DependencyInjection;
4
5 use Symfony\Component\DependencyInjection\ContainerBuilder;
6 use Symfony\Component\Config\FileLocator;
7 use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8 use Symfony\Component\DependencyInjection\Loader;
9
10 /**
11 * This is the class that loads and manages your bundle configuration.
12 *
13 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
14 */
15 class RapsysUserExtension extends Extension {
16 /**
17 * {@inheritdoc}
18 */
19 public function load(array $configs, ContainerBuilder $container) {
20 //Load configuration
21 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
22 $loader->load('services.yml');
23
24 //Load configuration
25 $configuration = $this->getConfiguration($configs, $container);
26 $config = $this->processConfiguration($configuration, $configs);
27
28 //Set default config in parameter
29 if (!$container->hasParameter($alias = $this->getAlias())) {
30 $container->setParameter($alias, $config[$alias]);
31 } else {
32 $config[$alias] = $container->getParameter($alias);
33 }
34
35 //Transform the two level tree in flat parameters
36 foreach($config[$alias] as $k => $v) {
37 foreach($v as $s => $d) {
38 //Set is as parameters
39 $container->setParameter($alias.'.'.$k.'.'.$s, $d);
40 }
41 }
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 public function getAlias() {
48 return 'rapsys_user';
49 }
50
51 /**
52 * The function that parses the array to flatten it into a one level depth array
53 *
54 * @param $array The config values array
55 * @param $path The current key path
56 * @param $depth The maxmium depth
57 * @param $sep The separator string
58 */
59 /*protected function flatten($array, $path, $depth = 10, $sep = '.') {
60 //Init res
61 $res = array();
62
63 //Pass through non hashed or empty array
64 if ($depth && is_array($array) && ($array === [] || array_keys($array) === range(0, count($array) - 1))) {
65 $res[$path] = $array;
66 //Flatten hashed array
67 } elseif ($depth && is_array($array)) {
68 foreach($array as $k => $v) {
69 $sub = $path ? $path.$sep.$k:$k;
70 $res += $this->flatten($v, $sub, $depth - 1, $sep);
71 }
72 //Pass scalar value directly
73 } else {
74 $res[$path] = $array;
75 }
76
77 //Return result
78 return $res;
79 }*/
80 }