From b5b2d0a721b4509d19d405bed57ea6e831fa3105 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 5 Mar 2014 14:13:21 -0600 Subject: [PATCH 1/3] [zendframework/zf2#4455] Allow passing ProcessorPluginManager to logger - Allows passing the ProcessorPluginManager to the Logger constructor - Adaptes the LoggerAbstractServiceFactory to inject the ProcessorPluginManager into the configuration prior to instantiating the logger. --- src/Logger.php | 7 ++++++ src/LoggerAbstractServiceFactory.php | 14 ++++++++++++ test/LoggerAbstractServiceFactoryTest.php | 27 +++++++++++++++++++++++ 3 files changed, 48 insertions(+) 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); + } } From 555d5d1b5d680f45677d5138158cd5d60d8aad66 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 5 Mar 2014 14:25:18 -0600 Subject: [PATCH 2/3] [zendframework/zf2#4455] Updated Logger abstract factory to reflect MVC - Use LogWriterManager and LogProcessorManager services instead. - Added group annotations to tests --- src/LoggerAbstractServiceFactory.php | 8 ++++---- test/LoggerAbstractServiceFactoryTest.php | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/LoggerAbstractServiceFactory.php b/src/LoggerAbstractServiceFactory.php index 43bb6ebd..4712ef07 100644 --- a/src/LoggerAbstractServiceFactory.php +++ b/src/LoggerAbstractServiceFactory.php @@ -100,9 +100,9 @@ protected function processConfig(&$config, ServiceLocatorInterface $services) if ((!isset($config['writer_plugin_manager']) || ! $config['writer_plugin_manager'] instanceof AbstractPluginManager) - && $services->has('Zend\Log\WriterPluginManager') + && $services->has('LogWriterManager') ) { - $config['writer_plugin_manager'] = $services->get('Zend\Log\WriterPluginManager'); + $config['writer_plugin_manager'] = $services->get('LogWriterManager'); } if (isset($config['processor_plugin_manager']) @@ -114,9 +114,9 @@ protected function processConfig(&$config, ServiceLocatorInterface $services) if ((!isset($config['processor_plugin_manager']) || ! $config['processor_plugin_manager'] instanceof AbstractPluginManager) - && $services->has('Zend\Log\ProcessorPluginManager') + && $services->has('LogProcessorManager') ) { - $config['processor_plugin_manager'] = $services->get('Zend\Log\ProcessorPluginManager'); + $config['processor_plugin_manager'] = $services->get('LogProcessorManager'); } if (!isset($config['writers'])) { diff --git a/test/LoggerAbstractServiceFactoryTest.php b/test/LoggerAbstractServiceFactoryTest.php index eaee5630..6c96da00 100644 --- a/test/LoggerAbstractServiceFactoryTest.php +++ b/test/LoggerAbstractServiceFactoryTest.php @@ -131,6 +131,9 @@ public function testRetrievesDatabaseServiceFromServiceManagerWhenEncounteringDb $this->assertAttributeSame($db, 'db', $writer); } + /** + * @group 4455 + */ public function testWillInjectWriterPluginManagerIfAvailable() { $writers = new WriterPluginManager(); @@ -140,7 +143,7 @@ public function testWillInjectWriterPluginManagerIfAvailable() $services = new ServiceManager(new ServiceManagerConfig(array( 'abstract_factories' => array('Zend\Log\LoggerAbstractServiceFactory'), ))); - $services->setService('Zend\Log\WriterPluginManager', $writers); + $services->setService('LogWriterManager', $writers); $services->setService('Config', array( 'log' => array( 'Application\Frontend' => array( @@ -156,6 +159,9 @@ public function testWillInjectWriterPluginManagerIfAvailable() $this->assertSame($mockWriter, $writer); } + /** + * @group 4455 + */ public function testWillInjectProcessorPluginManagerIfAvailable() { $processors = new ProcessorPluginManager(); @@ -165,7 +171,7 @@ public function testWillInjectProcessorPluginManagerIfAvailable() $services = new ServiceManager(new ServiceManagerConfig(array( 'abstract_factories' => array('Zend\Log\LoggerAbstractServiceFactory'), ))); - $services->setService('Zend\Log\ProcessorPluginManager', $processors); + $services->setService('LogProcessorManager', $processors); $services->setService('Config', array( 'log' => array( 'Application\Frontend' => array( From 431bf4c5e0493472682ca770a74491a8add92fe2 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 5 Mar 2014 14:26:09 -0600 Subject: [PATCH 3/3] [zendframework/zf2#4455] CS fixes - trailing whitespace --- src/Logger.php | 4 ++-- src/LoggerAbstractServiceFactory.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Logger.php b/src/Logger.php index f2ff7684..9feca3d5 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -149,14 +149,14 @@ public function __construct($options = null) } // Inject writer plugin manager, if available - if (isset($options['writer_plugin_manager']) + if (isset($options['writer_plugin_manager']) && $options['writer_plugin_manager'] instanceof AbstractPluginManager ) { $this->setWriterPluginManager($options['writer_plugin_manager']); } // Inject processor plugin manager, if available - if (isset($options['processor_plugin_manager']) + if (isset($options['processor_plugin_manager']) && $options['processor_plugin_manager'] instanceof AbstractPluginManager ) { $this->setProcessorPluginManager($options['processor_plugin_manager']); diff --git a/src/LoggerAbstractServiceFactory.php b/src/LoggerAbstractServiceFactory.php index 4712ef07..b4611e15 100644 --- a/src/LoggerAbstractServiceFactory.php +++ b/src/LoggerAbstractServiceFactory.php @@ -91,7 +91,7 @@ protected function getConfig(ServiceLocatorInterface $services) protected function processConfig(&$config, ServiceLocatorInterface $services) { - if (isset($config['writer_plugin_manager']) + if (isset($config['writer_plugin_manager']) && is_string($config['writer_plugin_manager']) && $services->has($config['writer_plugin_manager']) ) { @@ -105,7 +105,7 @@ protected function processConfig(&$config, ServiceLocatorInterface $services) $config['writer_plugin_manager'] = $services->get('LogWriterManager'); } - if (isset($config['processor_plugin_manager']) + if (isset($config['processor_plugin_manager']) && is_string($config['processor_plugin_manager']) && $services->has($config['processor_plugin_manager']) ) {