Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
34 changes: 24 additions & 10 deletions src/LoggerAbstractServiceFactory.php
Expand Up @@ -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]);
}
}
12 changes: 7 additions & 5 deletions test/LoggerAbstractServiceFactoryTest.php
Expand Up @@ -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(),
),
));
}
Expand All @@ -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'),
);
}

Expand All @@ -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'),
);
}

Expand Down

0 comments on commit 3fc0bdb

Please sign in to comment.