diff --git a/src/Logger.php b/src/Logger.php index 8b4c7f42..f2ff7684 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -155,6 +155,13 @@ public function __construct($options = null) $this->setWriterPluginManager($options['writer_plugin_manager']); } + // Inject processor plugin manager, if available + if (isset($options['processor_plugin_manager']) + && $options['processor_plugin_manager'] instanceof AbstractPluginManager + ) { + $this->setProcessorPluginManager($options['processor_plugin_manager']); + } + if (isset($options['writers']) && is_array($options['writers'])) { foreach ($options['writers'] as $writer) { if (!isset($writer['name'])) { diff --git a/src/LoggerAbstractServiceFactory.php b/src/LoggerAbstractServiceFactory.php index 54961bf9..43bb6ebd 100644 --- a/src/LoggerAbstractServiceFactory.php +++ b/src/LoggerAbstractServiceFactory.php @@ -105,6 +105,20 @@ protected function processConfig(&$config, ServiceLocatorInterface $services) $config['writer_plugin_manager'] = $services->get('Zend\Log\WriterPluginManager'); } + if (isset($config['processor_plugin_manager']) + && is_string($config['processor_plugin_manager']) + && $services->has($config['processor_plugin_manager']) + ) { + $config['processor_plugin_manager'] = $services->get($config['processor_plugin_manager']); + } + + if ((!isset($config['processor_plugin_manager']) + || ! $config['processor_plugin_manager'] instanceof AbstractPluginManager) + && $services->has('Zend\Log\ProcessorPluginManager') + ) { + $config['processor_plugin_manager'] = $services->get('Zend\Log\ProcessorPluginManager'); + } + if (!isset($config['writers'])) { return; } diff --git a/test/LoggerAbstractServiceFactoryTest.php b/test/LoggerAbstractServiceFactoryTest.php index 4798c1a4..eaee5630 100644 --- a/test/LoggerAbstractServiceFactoryTest.php +++ b/test/LoggerAbstractServiceFactoryTest.php @@ -9,6 +9,7 @@ namespace ZendTest\Log; +use Zend\Log\ProcessorPluginManager; use Zend\Log\WriterPluginManager; use Zend\Log\Writer\Db as DbWriter; use Zend\Mvc\Service\ServiceManagerConfig; @@ -154,4 +155,30 @@ public function testWillInjectWriterPluginManagerIfAvailable() $writer = $logWriters->current(); $this->assertSame($mockWriter, $writer); } + + public function testWillInjectProcessorPluginManagerIfAvailable() + { + $processors = new ProcessorPluginManager(); + $mockProcessor = $this->getMock('Zend\Log\Processor\ProcessorInterface'); + $processors->setService('CustomProcessor', $mockProcessor); + + $services = new ServiceManager(new ServiceManagerConfig(array( + 'abstract_factories' => array('Zend\Log\LoggerAbstractServiceFactory'), + ))); + $services->setService('Zend\Log\ProcessorPluginManager', $processors); + $services->setService('Config', array( + 'log' => array( + 'Application\Frontend' => array( + 'writers' => array(array('name' => 'Null')), + 'processors' => array(array('name' => 'CustomProcessor')), + ), + ), + )); + + $log = $services->get('Application\Frontend'); + $logProcessors = $log->getProcessors(); + $this->assertEquals(1, count($logProcessors)); + $processor = $logProcessors->current(); + $this->assertSame($mockProcessor, $processor); + } }