diff --git a/src/LoggerAbstractServiceFactory.php b/src/LoggerAbstractServiceFactory.php index 0d19d807..56f389e3 100644 --- a/src/LoggerAbstractServiceFactory.php +++ b/src/LoggerAbstractServiceFactory.php @@ -20,26 +20,40 @@ class LoggerAbstractServiceFactory implements AbstractFactoryInterface { /** - * @param ServiceLocatorInterface $serviceLocator - * @param string $name - * @param string $requestedName + * @param ServiceLocatorInterface $serviceLocator + * @param string $name + * @param string $requestedName * @return bool */ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { - $config = $serviceLocator->get('Config'); - return isset($config['log'][$requestedName]); + if ('logger\\' != substr(strtolower($requestedName), 0, 7)) { + return false; + } + + $config = $serviceLocator->get('Config'); + if (!isset($config['log'])) { + return false; + } + + $config = array_change_key_case($config['log']); + $service = substr(strtolower($requestedName), 7); + + return isset($config[$service]); } /** - * @param ServiceLocatorInterface $serviceLocator - * @param string $name - * @param string $requestedName + * @param ServiceLocatorInterface $serviceLocator + * @param string $name + * @param string $requestedName * @return \Zend\Log\Logger */ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { - $config = $serviceLocator->get('Config'); - return new Logger($config['log'][$requestedName]); + $config = $serviceLocator->get('Config'); + $config = array_change_key_case($config['log']); + $service = substr(strtolower($requestedName), 7); + + return new Logger($config[$service]); } } diff --git a/test/LoggerAbstractServiceFactoryTest.php b/test/LoggerAbstractServiceFactoryTest.php index cab2f44f..eea941e8 100644 --- a/test/LoggerAbstractServiceFactoryTest.php +++ b/test/LoggerAbstractServiceFactoryTest.php @@ -39,8 +39,8 @@ protected function setUp() $this->serviceManager->setService('Config', array( 'log' => array( - 'Application\Frontend\Logger' => array(), - 'Application\Backend\Logger' => array(), + 'Application\Frontend' => array(), + 'Application\Backend' => array(), ), )); } @@ -51,8 +51,8 @@ protected function setUp() public function providerValidLoggerService() { return array( - array('Application\Frontend\Logger'), - array('Application\Backend\Logger'), + array('Logger\Application\Frontend'), + array('Logger\Application\Backend'), ); } @@ -62,7 +62,9 @@ public function providerValidLoggerService() public function providerInvalidLoggerService() { return array( - array('Application\Unknown\Logger'), + array('Logger\Application\Unknown'), + array('Application\Frontend'), + array('Application\Backend'), ); }