]> Raphaƫl G. Git Repositories - packbundle/blob - DependencyInjection/RapsysPackExtension.php
Update to 4.x new path
[packbundle] / DependencyInjection / RapsysPackExtension.php
1 <?php
2
3 namespace Rapsys\PackBundle\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 RapsysPackExtension 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(\dirname(__DIR__).'/Resources/config'));
22 $loader = new Loader\YamlFileLoader($container, new FileLocator('config/packages'));
23 $loader->load($this->getAlias().'.yaml');
24
25 //Load configuration
26 $configuration = $this->getConfiguration($configs, $container);
27 $config = $this->processConfiguration($configuration, $configs);
28
29 //Set default config in parameter
30 if (!$container->hasParameter($alias = $this->getAlias())) {
31 $container->setParameter($alias, $config[$alias]);
32 //Fill missing entries
33 } else {
34 //Change in config flag
35 $change = false;
36
37 //Iterate on each user configuration keys
38 foreach($container->getParameter($alias) as $k => $v) {
39 //Check if value is an array
40 if (is_array($v)) {
41 //Iterate on each array keys
42 foreach($v as $sk => $sv) {
43 //Check if sub value is an array
44 if (is_array($sv)) {
45 //TODO: implement sub sub key merging ? (or recursive ?)
46 @trigger_error('Nested level > 2 not yet implemented here', E_USER_ERROR);
47 //Save sub value
48 } else {
49 //Trigger changed flag
50 $change = true;
51 //Replace default value with user provided one
52 $config[$alias][$k][$sk] = $sv;
53 }
54 }
55 //Save value
56 } else {
57 //Trigger changed flag
58 $change = true;
59 //Replace default value with user provided one
60 $config[$alias][$k] = $v;
61 }
62 }
63
64 //Check if change occured
65 if ($change) {
66 //Save parameters
67 $container->setParameter($alias, $config[$alias]);
68 }
69 }
70 }
71
72 /**
73 * {@inheritdoc}
74 */
75 public function getConfiguration(array $configs, ContainerBuilder $container) {
76 //Get configuration instance with resolved public path
77 return new Configuration($container->getParameter('kernel.project_dir').'/public/');
78 }
79
80 /**
81 * {@inheritdoc}
82 */
83 public function getAlias() {
84 return 'rapsys_pack';
85 }
86 }