3 namespace Rapsys\AirBundle\DependencyInjection
; 
   5 use Symfony\Component\DependencyInjection\ContainerBuilder
; 
   6 use Symfony\Component\DependencyInjection\Extension\Extension
; 
   7 use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface
; 
   8 use Symfony\Component\Translation\Loader\ArrayLoader
; 
  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 RapsysAirExtension 
extends Extension 
implements PrependExtensionInterface 
{ 
  17          * Prepend the configuration 
  19          * @desc Preload the configuration to allow sourcing as parameters 
  22         public function prepend(ContainerBuilder 
$container) { 
  23                 //Process the configuration 
  24                 $configs = $container->getExtensionConfig($this->getAlias()); 
  27                 $configuration = $this->getConfiguration($configs, $container); 
  29                 //Process the configuration to get merged config 
  30                 $config = $this->processConfiguration($configuration, $configs); 
  32                 //Detect when no user configuration is provided 
  33                 if ($configs === [[]]) { 
  34                         //Prepend default config 
  35                         $container->prependExtensionConfig($this->getAlias(), $config); 
  38                 //Save configuration in parameters 
  39                 $container->setParameter($this->getAlias(), $config); 
  41                 //Store flattened array in parameters 
  42                 foreach($this->flatten($config, $this->getAlias()) as $k => $v) { 
  43                         $container->setParameter($k, $v); 
  50         public function load(array $configs, ContainerBuilder 
$container) { 
  56         public function getAlias() { 
  61          * The function that parses the array to flatten it into a one level depth array 
  63          * @param $array        The config values array 
  64          * @param $path         The current key path 
  65          * @param $depth        The maxmium depth 
  66          * @param $sep          The separator string 
  68         protected function flatten($array, $path = '', $depth = 10, $sep = '.') { 
  72                 //Pass through non hashed or empty array 
  73                 if ($depth && is_array($array) && ($array === [] || array_keys($array) === range(0, count($array) - 1))) { 
  75                 //Flatten hashed array 
  76                 } elseif ($depth && is_array($array)) { 
  77                         foreach($array as $k => $v) { 
  78                                 $sub = $path ? $path.$sep.$k:$k; 
  79                                 $res +
= $this->flatten($v, $sub, $depth - 1, $sep); 
  81                 //Pass scalar value directly