Skip to content

Commit

Permalink
Merge pull request #128 from DonCallisto/patch-2
Browse files Browse the repository at this point in the history
Update DebrilRssAtomExtension.php
  • Loading branch information
alexdebril authored Feb 1, 2017
2 parents cdfac2d + 69f6308 commit dfabfba
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions DependencyInjection/DebrilRssAtomExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Debril\RssAtomBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\Config\FileLocator;
Expand All @@ -13,7 +14,7 @@
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class DebrilRssAtomExtension extends Extension
class DebrilRssAtomExtension extends Extension implements CompilerPassInterface
{

/**
Expand All @@ -40,30 +41,13 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$this->setDefinition($container, 'logger', 'Psr\Log\NullLogger');

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');

$this->setDateFormats($container, $config);
$container->setParameter('debril_rss_atom.private_feeds', $config['private']);
}

/**
* @param ContainerBuilder $container
* @param $serviceName
* @param $className
* @return $this
*/
protected function setDefinition(ContainerBuilder $container, $serviceName, $className)
{
if ( ! $container->hasDefinition($serviceName) && ! $container->hasAlias($serviceName)) {
$container->setDefinition($serviceName, new Definition($className));
}

return $this;
}

/**
* @param ContainerBuilder $container
* @param array $config
Expand All @@ -82,4 +66,27 @@ protected function setDateFormats(ContainerBuilder $container, array $config)

return $this;
}

/**
* @param ContainerBuilder $builder
*/
public function process(ContainerBuilder $container)
{
$this->setDefinition($container, 'logger', 'Psr\Log\NullLogger');
}

/**
* @param ContainerBuilder $container
* @param $serviceName
* @param $className
* @return $this
*/
protected function setDefinition(ContainerBuilder $container, $serviceName, $className)
{
if ( ! $container->has($serviceName) ) {
$container->setDefinition($serviceName, new Definition($className));
}

return $this;
}
}

0 comments on commit dfabfba

Please sign in to comment.