3 namespace Rapsys\PackBundle\DependencyInjection
;
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
;
11 * This is the class that loads and manages your bundle configuration.
13 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
15 class RapsysPackExtension
extends Extension
{
19 public function load(array $configs, ContainerBuilder
$container) {
21 $loader = new Loader\
YamlFileLoader($container, new FileLocator('config/packages'));
22 $loader->load($this->getAlias().'.yaml');
25 $configuration = $this->getConfiguration($configs, $container);
26 $config = $this->processConfiguration($configuration, $configs);
28 //Set default config in parameter
29 if (!$container->hasParameter($alias = $this->getAlias())) {
30 $container->setParameter($alias, $config[$alias]);
31 //Fill missing entries
33 //Change in config flag
36 //Iterate on each user configuration keys
37 foreach($container->getParameter($alias) as $k => $v) {
38 //Check if value is an array
40 //Iterate on each array keys
41 foreach($v as $sk => $sv) {
42 //Check if sub value is an array
44 //TODO: implement sub sub key merging ? (or recursive ?)
45 @trigger_error('Nested level > 2 not yet implemented here', E_USER_ERROR
);
48 //Trigger changed flag
50 //Replace default value with user provided one
51 $config[$alias][$k][$sk] = $sv;
56 //Trigger changed flag
58 //Replace default value with user provided one
59 $config[$alias][$k] = $v;
63 //Check if change occured
66 $container->setParameter($alias, $config[$alias]);
74 public function getConfiguration(array $configs, ContainerBuilder
$container) {
75 //Get configuration instance with resolved public path
76 return new Configuration($container->getParameter('kernel.project_dir').'/public/');
82 public function getAlias() {