[ZendBundle] added a simple way to add new writers (add a service with a zend.logger.writer tag)
This commit is contained in:
parent
7fdc61f272
commit
aea712d8a2
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Bundle\ZendBundle\DependencyInjection\Compiler;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||||
|
*
|
||||||
|
* 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 <fabien.potencier@symfony-project.com>
|
||||||
|
*/
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,12 +16,10 @@
|
|||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
<service id="zend.logger" class="%zend.logger.class%">
|
<service id="zend.logger" class="%zend.logger.class%" />
|
||||||
<call method="addWriter"><argument type="service" id="zend.logger.writer.filesystem" /></call>
|
|
||||||
<call method="addWriter"><argument type="service" id="zend.logger.writer.debug" /></call>
|
|
||||||
</service>
|
|
||||||
|
|
||||||
<service id="zend.logger.writer.filesystem" class="%zend.logger.writer.filesystem.class%">
|
<service id="zend.logger.writer.filesystem" class="%zend.logger.writer.filesystem.class%">
|
||||||
|
<tag name="zend.logger.writer" />
|
||||||
<argument>%zend.logger.path%</argument>
|
<argument>%zend.logger.path%</argument>
|
||||||
<call method="addFilter"><argument type="service" id="zend.logger.filter" /></call>
|
<call method="addFilter"><argument type="service" id="zend.logger.filter" /></call>
|
||||||
<call method="setFormatter"><argument type="service" id="zend.formatter.filesystem" /></call>
|
<call method="setFormatter"><argument type="service" id="zend.formatter.filesystem" /></call>
|
||||||
@ -32,6 +30,7 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="zend.logger.writer.debug" class="%zend.logger.writer.debug.class%">
|
<service id="zend.logger.writer.debug" class="%zend.logger.writer.debug.class%">
|
||||||
|
<tag name="zend.logger.writer" />
|
||||||
<call method="addFilter"><argument type="service" id="zend.logger.filter" /></call>
|
<call method="addFilter"><argument type="service" id="zend.logger.filter" /></call>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace Symfony\Bundle\ZendBundle;
|
namespace Symfony\Bundle\ZendBundle;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
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.
|
* This file is part of the Symfony framework.
|
||||||
@ -20,4 +22,10 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
|
|||||||
*/
|
*/
|
||||||
class ZendBundle extends Bundle
|
class ZendBundle extends Bundle
|
||||||
{
|
{
|
||||||
|
public function registerExtensions(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
parent::registerExtensions($container);
|
||||||
|
|
||||||
|
$container->addCompilerPass(new ZendLoggerWriterPass());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user