Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
NotLoginMiddleware | |
0.00% |
0 / 6 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handleBefore | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
handleAfter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Middleware; |
6 | |
7 | use PeServer\App\Models\SessionKey; |
8 | use PeServer\Core\Environment; |
9 | use PeServer\Core\Http\HttpResponse; |
10 | use PeServer\Core\Http\HttpStatus; |
11 | use PeServer\Core\Log\ILogger; |
12 | use PeServer\Core\Mvc\Middleware\IMiddleware; |
13 | use PeServer\Core\Mvc\Middleware\MiddlewareArgument; |
14 | use PeServer\Core\Mvc\Middleware\MiddlewareResult; |
15 | |
16 | final class NotLoginMiddleware implements IMiddleware |
17 | { |
18 | public function __construct( |
19 | private ILogger $logger |
20 | ) { |
21 | } |
22 | |
23 | #region IMiddleware |
24 | |
25 | public function handleBefore(MiddlewareArgument $argument): MiddlewareResult |
26 | { |
27 | if ($argument->stores->session->tryGet(SessionKey::ACCOUNT, $account)) { |
28 | $this->logger->warn('login user: {0}', $account); |
29 | return MiddlewareResult::error(HttpStatus::NotFound); |
30 | } |
31 | |
32 | return MiddlewareResult::none(); |
33 | } |
34 | |
35 | public function handleAfter(MiddlewareArgument $argument, HttpResponse $response): MiddlewareResult |
36 | { |
37 | return MiddlewareResult::none(); |
38 | } |
39 | |
40 | #endregion |
41 | } |