Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
NotLoginMiddleware
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 handleBefore
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 handleAfter
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Middleware;
6
7use PeServer\App\Models\SessionKey;
8use PeServer\Core\Environment;
9use PeServer\Core\Http\HttpResponse;
10use PeServer\Core\Http\HttpStatus;
11use PeServer\Core\Log\ILogger;
12use PeServer\Core\Mvc\Middleware\IMiddleware;
13use PeServer\Core\Mvc\Middleware\MiddlewareArgument;
14use PeServer\Core\Mvc\Middleware\MiddlewareResult;
15
16final 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}