From efba921f0ff585d124d4f56d2edbf39c600f60dc Mon Sep 17 00:00:00 2001 From: mikemix Date: Fri, 17 Jul 2015 09:27:50 +0200 Subject: [PATCH] Use service trait --- src/Controller/CacheClearController.php | 5 ++++- src/Service/DiFactory.php | 4 +++- src/ServiceManager/DiAbstractFactory.php | 9 ++++++--- test/Controller/CacheClearControllerTest.php | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Controller/CacheClearController.php b/src/Controller/CacheClearController.php index 95f5774..d467034 100644 --- a/src/Controller/CacheClearController.php +++ b/src/Controller/CacheClearController.php @@ -1,12 +1,15 @@ storage->removeItem(md5($fqcn)); + $this->storage->removeItem($this->getHash($fqcn)); return 0; } diff --git a/src/Service/DiFactory.php b/src/Service/DiFactory.php index 991c1bd..0fc81e7 100644 --- a/src/Service/DiFactory.php +++ b/src/Service/DiFactory.php @@ -3,12 +3,14 @@ use mxdiModule\ServiceManager\DiAbstractFactory; use mxdiModule\Service\Exception\CannotCreateService; +use mxdiModule\Traits\ServiceTrait; use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorAwareTrait; final class DiFactory implements ServiceLocatorAwareInterface { use ServiceLocatorAwareTrait; + use ServiceTrait; /** @var DiAbstractFactory */ private $diAbstractFactory; @@ -39,7 +41,7 @@ public function __invoke($fqcn) */ public function get($fqcn) { - $serviceName = strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $fqcn)); + $serviceName = $this->getCanonicalName($fqcn); if ($this->diAbstractFactory->canCreateServiceWithName($this->serviceLocator, $serviceName, $fqcn)) { return $this->diAbstractFactory->createServiceWithName($this->serviceLocator, $serviceName, $fqcn); diff --git a/src/ServiceManager/DiAbstractFactory.php b/src/ServiceManager/DiAbstractFactory.php index 1926ce4..a002b26 100644 --- a/src/ServiceManager/DiAbstractFactory.php +++ b/src/ServiceManager/DiAbstractFactory.php @@ -2,6 +2,7 @@ namespace mxdiModule\ServiceManager; use mxdiModule\Service\ExtractorInterface; +use mxdiModule\Traits\ServiceTrait; use Zend\Cache\Storage\Adapter\AbstractAdapter; use Zend\Cache\Storage\StorageInterface; use Zend\ServiceManager\AbstractFactoryInterface; @@ -11,6 +12,8 @@ class DiAbstractFactory implements AbstractFactoryInterface { + use ServiceTrait; + /** @var array */ protected $config; @@ -46,7 +49,7 @@ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator } $this->initializeCache($serviceLocator); - $this->setChangeSet($this->cache->getItem(md5($name))); + $this->setChangeSet($this->cache->getItem($this->getHash($name))); if ($this->getChangeSet() instanceof ChangeSet) { // Positive result available via cache @@ -61,13 +64,13 @@ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator if ($this->getChangeSet()->isAnnotated()) { // Service is annotated to cache results - $this->cache->setItem(md5($name), $this->getChangeSet()); + $this->cache->setItem($this->getHash($name), $this->getChangeSet()); return true; } // Service is not annotated // Cache false for it - $this->cache->setItem(md5($name), false); + $this->cache->setItem($this->getHash($name), false); return false; } diff --git a/test/Controller/CacheClearControllerTest.php b/test/Controller/CacheClearControllerTest.php index eb36777..fc13764 100644 --- a/test/Controller/CacheClearControllerTest.php +++ b/test/Controller/CacheClearControllerTest.php @@ -53,7 +53,7 @@ public function testFlushOne() $storage->expects($this->once()) ->method('removeItem') - ->with($this->equalTo(md5($fqcn))); + ->with($this->equalTo(md5('appservicetestservice'))); $this->plugin->expects($this->atLeastOnce()) ->method('__invoke')