Skip to content

Commit

Permalink
Add configuration for third party bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
cluster28 committed May 3, 2019
1 parent bc82cf1 commit 35366ee
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
58 changes: 49 additions & 9 deletions DependencyInjection/MonologConfigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ public function prepend(ContainerBuilder $container)
$this->monologConfigs = $this->mergeConfiguration($this->monologConfigs, new FileImporter($config['sources']['files']));
}

$this->addConfig('config', $container);
$this->addConfig($container->getParameter("kernel.environment"), $container);
foreach ($this->monologConfigs as $definition => $arrayValues) {
$this->addDefinitionConfigs($definition, $container);
}

$this->addParameters($container->getParameter("kernel.environment"), $container);
}

/**
Expand All @@ -55,23 +58,60 @@ private function mergeConfiguration($monologConfigs, ImporterInterface $importer
}

/**
* @param $env
* @param $definition
* @param ContainerBuilder $container
*/
private function addDefinitionConfigs($definition, ContainerBuilder $container)
{
if ($container->hasExtension($definition) || $definition === 'app') {
foreach ($this->monologConfigs[$definition] as $environment => $environmentConfig) {
if (in_array($environment, ['config', $container->getParameter("kernel.environment")])) {
$this->addHandlers($environmentConfig, $container);
}
}
}
}

/**
* @param $environmentConfig
* @param ContainerBuilder $container
*/
private function addConfig($env, ContainerBuilder $container)
private function addHandlers($environmentConfig, ContainerBuilder $container)
{
if (isset($this->monologConfigs['monolog']) && isset($this->monologConfigs['monolog'][$env])) {
foreach ($this->monologConfigs['monolog'][$env]['handlers'] as $name => $values) {
if (isset($environmentConfig['handlers'])) {
foreach ($environmentConfig['handlers'] as $name => $values) {
$container->prependExtensionConfig('monolog', [
'handlers' => [$name => $values]
]);
}
}
}

if (isset($this->monologConfigs['parameters']) && isset($this->monologConfigs['parameters'][$env])) {
foreach ($this->monologConfigs['parameters'][$env] as $name => $value) {
$container->setParameter($name, $value);
/**
* @param $currentEnvironment
* @param ContainerBuilder $container
*/
private function addParameters($currentEnvironment, ContainerBuilder $container)
{
if (!$parameters = $this->getConfigParameters()) {
return;
}

foreach ($parameters as $environment => $arrayParameters) {
if (in_array($environment, ['config', $currentEnvironment])) {
foreach ($arrayParameters as $name => $value) {
$container->setParameter($name, $value);
}
}
}

}

/**
* @return mixed|null
*/
private function getConfigParameters()
{
return isset($this->monologConfigs['parameters']) ? $this->monologConfigs['parameters'] : null ;
}
}
2 changes: 1 addition & 1 deletion Resources/config/monolog_config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
monolog:
app:
config:
handlers:
mail:
Expand Down

0 comments on commit 35366ee

Please sign in to comment.