-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSessionMiddleware.php
More file actions
48 lines (40 loc) · 1.39 KB
/
SessionMiddleware.php
File metadata and controls
48 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace Dot\Session;
use Dot\Session\Options\SessionOptions;
use Laminas\Session\Container;
use Laminas\Session\SessionManager;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use function time;
class SessionMiddleware implements MiddlewareInterface
{
protected SessionManager $defaultSessionManager;
protected SessionOptions $options;
public function __construct(
SessionManager $sessionManager,
SessionOptions $options
) {
$this->defaultSessionManager = $sessionManager;
$this->options = $options;
Container::setDefaultManager($sessionManager);
}
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface {
$now = time();
if (
isset($this->defaultSessionManager->getStorage()['LAST_ACTIVITY'])
&&
($now - $this->defaultSessionManager->getStorage()['LAST_ACTIVITY'])
> $this->options->getRememberMeInactive()
) {
$this->defaultSessionManager->destroy(['send_expire_cookie' => true, 'clear_storage' => true]);
$this->defaultSessionManager->start();
}
return $handler->handle($request);
}
}