Skip to content

Commit de75f88

Browse files
authored
Merge pull request #4 from doctena-org/v2
V2 : Laminas3 support
2 parents a56cc92 + cb52fe5 commit de75f88

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=7.0",
20+
"php": ">=8.0",
2121
"laminas/laminas-modulemanager": "^2.5 || ^3.0",
2222
"laminas/laminas-eventmanager": "^2.5 || ^3.0",
2323
"laminas/laminas-mvc": "^2.5 || ^3.0",

src/SlmCache/Listener/Cache.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040

4141
namespace SlmCache\Listener;
4242

43+
use Laminas\Cache\Storage\StorageInterface;
44+
use Laminas\Cache\StorageFactory;
4345
use Laminas\EventManager\AbstractListenerAggregate;
4446
use Laminas\EventManager\EventManagerInterface;
45-
use Laminas\Mvc\MvcEvent;
46-
use Laminas\Mvc\Router\RouteMatch;
4747
use Laminas\Http\Response;
48+
use Laminas\Mvc\MvcEvent;
49+
use Laminas\Router\Http\RouteMatch;
4850
use Laminas\ServiceManager\ServiceLocatorInterface;
49-
use Laminas\Cache\StorageFactory;
50-
use Laminas\Cache\Storage\StorageInterface;
5151

5252
class Cache extends AbstractListenerAggregate
5353
{
@@ -70,7 +70,7 @@ public function __construct(ServiceLocatorInterface $sl)
7070
/**
7171
* {@inheritDoc}
7272
*/
73-
public function attach(EventManagerInterface $events)
73+
public function attach(EventManagerInterface $events, $priority = 1)
7474
{
7575
$events->attach(MvcEvent::EVENT_ROUTE, array($this, 'matchRoute'));
7676
$events->attach(MvcEvent::EVENT_FINISH, array($this, 'saveRoute'));
@@ -113,20 +113,20 @@ protected function match(MvcEvent $e)
113113
return;
114114
}
115115

116-
$route = $match->getMatchedRouteName();
116+
$route = $match->getMatchedRouteName();
117117
$routeParameters = $match->getParams();
118118
$config = $this->serviceLocator->get('Config');
119119
$routes = $config['slm_cache']['routes'];
120120

121121
if (!array_key_exists($route, $routes)) {
122122
return;
123123
}
124-
$config = (array) $routes[$route];
124+
$config = (array)$routes[$route];
125125

126126
// Match HTTP request method to configured methods
127127
if (array_key_exists('match_method', $config)) {
128-
$methods = (array) $config['match_method'];
129-
$method = $e->getRequest()->getMethod();
128+
$methods = (array)$config['match_method'];
129+
$method = $e->getRequest()->getMethod();
130130

131131
if (!in_array($method, $methods)) {
132132
return;
@@ -135,7 +135,7 @@ protected function match(MvcEvent $e)
135135

136136
// Match route request parameters to configured parameters
137137
if (array_key_exists('match_route_params', $config)) {
138-
$params = (array) $config['match_route_params'];
138+
$params = (array)$config['match_route_params'];
139139

140140
foreach ($params as $name => $value) {
141141
// There is a specific route parameter
@@ -150,24 +150,24 @@ protected function match(MvcEvent $e)
150150
}
151151
}
152152

153-
$match = ['route' => $route, 'config' => $config, 'parameters' => $routeParameters];
153+
$match = ['route' => $route, 'config' => $config, 'parameters' => $routeParameters];
154154
$this->match = $match;
155155

156156
return $match;
157157
}
158158

159159
protected function fromCache(MvcEvent $e, $match)
160160
{
161-
$key = $this->getCacheKey($match);
162-
$cache = $this->getCache($e);
161+
$key = $this->getCacheKey($match);
162+
$cache = $this->getCache($e);
163163

164164
$response = $e->getResponse();
165165

166166
if (($result = $cache->getItem($key))) {
167167
$response->setContent(
168168
empty($this->serviceLocator->get('Config')['slm_cache']['use_compression'])
169-
? $result
170-
: gzuncompress($result)
169+
? $result
170+
: gzuncompress($result)
171171
);
172172
$response->getHeaders()->addHeaderLine('X-Slm-Cache', 'Fetch: Hit; route=' . $match['route']);
173173
$e->setParam('cached', true);
@@ -180,8 +180,8 @@ protected function fromCache(MvcEvent $e, $match)
180180

181181
protected function storeCache(MvcEvent $e, $match)
182182
{
183-
$key = $this->getCacheKey($match);
184-
$cache = $this->getCache($e);
183+
$key = $this->getCacheKey($match);
184+
$cache = $this->getCache($e);
185185

186186
$response = $e->getResponse();
187187
$response->getHeaders()->addHeaderLine('X-Slm-Cache', 'Storage: Success; route=' . $match['route']);
@@ -218,6 +218,6 @@ protected function getCache(MvcEvent $e)
218218
*/
219219
protected function getCacheKey(array $match)
220220
{
221-
return $this->cache_prefix.sha1(serialize($match));
221+
return $this->cache_prefix . sha1(serialize($match));
222222
}
223223
}

0 commit comments

Comments
 (0)