From aea712d8a20ed6a0cb46b49726b0a2cf5b150bf9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 4 Jan 2011 14:46:24 +0100 Subject: [PATCH] [ZendBundle] added a simple way to add new writers (add a service with a zend.logger.writer tag) --- .../Compiler/ZendLoggerWriterPass.php | 37 +++++++++++++++++++ .../ZendBundle/Resources/config/logger.xml | 7 ++-- src/Symfony/Bundle/ZendBundle/ZendBundle.php | 8 ++++ 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Bundle/ZendBundle/DependencyInjection/Compiler/ZendLoggerWriterPass.php diff --git a/src/Symfony/Bundle/ZendBundle/DependencyInjection/Compiler/ZendLoggerWriterPass.php b/src/Symfony/Bundle/ZendBundle/DependencyInjection/Compiler/ZendLoggerWriterPass.php new file mode 100644 index 0000000000..fb78b30670 --- /dev/null +++ b/src/Symfony/Bundle/ZendBundle/DependencyInjection/Compiler/ZendLoggerWriterPass.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Adds tagged zend.logger.writer services to zend.logger service + * + * @author Fabien Potencier + */ +class ZendLoggerWriterPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + if (false === $container->hasDefinition('zend.logger')) { + return; + } + + $definition = $container->getDefinition('zend.logger'); + + foreach ($container->findTaggedServiceIds('zend.logger.writer') as $id => $attributes) { + $definition->addMethodCall('addWriter', array(new Reference($id))); + } + } +} diff --git a/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml b/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml index 65277672a2..d976cdbee1 100644 --- a/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml +++ b/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml @@ -16,12 +16,10 @@ - - - - + + %zend.logger.path% @@ -32,6 +30,7 @@ + diff --git a/src/Symfony/Bundle/ZendBundle/ZendBundle.php b/src/Symfony/Bundle/ZendBundle/ZendBundle.php index 5919603325..076dea286f 100644 --- a/src/Symfony/Bundle/ZendBundle/ZendBundle.php +++ b/src/Symfony/Bundle/ZendBundle/ZendBundle.php @@ -3,6 +3,8 @@ namespace Symfony\Bundle\ZendBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Bundle\ZendBundle\DependencyInjection\Compiler\ZendLoggerWriterPass; /* * This file is part of the Symfony framework. @@ -20,4 +22,10 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; */ class ZendBundle extends Bundle { + public function registerExtensions(ContainerBuilder $container) + { + parent::registerExtensions($container); + + $container->addCompilerPass(new ZendLoggerWriterPass()); + } }