Created
June 10, 2016 12:24
-
-
Save garex/bb991f14412dca823f74086684b4070a to your computer and use it in GitHub Desktop.
Tree-like parameters from services into flat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\AppBundle\DependencyInjection; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\Config\FileLocator; | |
use Symfony\Component\DependencyInjection\Loader; | |
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | |
class VendorAppExtension extends Extension | |
{ | |
final public function load(array $configs, ContainerBuilder $container) | |
{ | |
$this->loadInternal($this->processConfiguration($this->getConfiguration($configs, $container), $configs), $container); | |
} | |
protected function loadInternal(array $mergedConfig, ContainerBuilder $container) | |
{ | |
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); | |
$loader->load('services.yml'); | |
$this->flatifyParameter($container, $this->getAlias()); | |
} | |
private function flatifyParameter(ContainerBuilder $container, $globalKey, $value = null) | |
{ | |
if (is_null($value)) { | |
$value = $container->getParameter($globalKey); | |
} | |
if (is_array($value)) { | |
foreach ($value as $key => $value) { | |
$this->flatifyParameter($container, $globalKey . '.' . $key, $value); | |
} | |
} else { | |
$container->setParameter($globalKey, $value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment