diff --git a/config/module.config.php b/config/module.config.php index 8d02e50..7ba48f8 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -5,5 +5,6 @@ 'cache' => null, 'routes' => array( ), + 'priority' => 1, ), ); \ No newline at end of file diff --git a/src/SlmCache/Listener/Cache.php b/src/SlmCache/Listener/Cache.php index 031e25a..f8c5c72 100644 --- a/src/SlmCache/Listener/Cache.php +++ b/src/SlmCache/Listener/Cache.php @@ -52,6 +52,7 @@ class Cache extends AbstractListenerAggregate { protected $cache_prefix = 'slm_cache_'; + protected $cache_priority = 1; protected $match; protected $serviceLocator; @@ -65,15 +66,19 @@ public function __construct(ServiceLocatorInterface $sl) if (isset($config['slm_cache']['cache_prefix'])) { $this->cache_prefix = $config['slm_cache']['cache_prefix']; } - } + + if (isset($config['slm_cache']['priority'])) { + $this->cache_priority = $config['slm_cache']['priority']; + } + } /** * {@inheritDoc} */ public function attach(EventManagerInterface $events) { - $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'matchRoute')); - $events->attach(MvcEvent::EVENT_FINISH, array($this, 'saveRoute')); + $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'matchRoute'), $this->cache_priority); + $events->attach(MvcEvent::EVENT_FINISH, array($this, 'saveRoute'), $this->cache_priority); } public function matchRoute(MvcEvent $e) diff --git a/tests/SlmCacheTest/Listener/CacheTest.php b/tests/SlmCacheTest/Listener/CacheTest.php index 70cbd37..edd3520 100644 --- a/tests/SlmCacheTest/Listener/CacheTest.php +++ b/tests/SlmCacheTest/Listener/CacheTest.php @@ -176,4 +176,43 @@ public function testCachePrefixIsDefault() PHPUnit_Framework_Assert::readAttribute($listener, 'cache_prefix') ); } + + public function testCachePriorityIsUserDefined() + { + $config = array( + 'slm_cache' => array( + 'priority' => 200 + ) + ); + + $sl = new ServiceManager; + $sl->setService('Config', $config); + + $listener = new CacheListener($sl); + + $this->assertEquals( + $config['slm_cache']['priority'], + PHPUnit_Framework_Assert::readAttribute($listener, 'cache_priority') + ); + } + + public function testCachePriorityIsDefault() + { + $config = array( + 'slm_cache' => array( + 'cache' => array() + ) + ); + + $sl = new ServiceManager; + $sl->setService('Config', $config); + + $listener = new CacheListener($sl); + + $this->assertEquals( + 1, + PHPUnit_Framework_Assert::readAttribute($listener, 'cache_priority') + ); + } + } \ No newline at end of file