Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
HttpsMiddleware | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handleBefore | |
0.00% |
0 / 6 |
|
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\Core\Mvc\Middleware; |
6 | |
7 | use PeServer\Core\Collection\Arr; |
8 | use PeServer\Core\Http\HttpResponse; |
9 | use PeServer\Core\Http\HttpStatus; |
10 | use PeServer\Core\Log\ILogger; |
11 | use PeServer\Core\Mvc\Middleware\IMiddleware; |
12 | use PeServer\Core\Mvc\Middleware\MiddlewareArgument; |
13 | use PeServer\Core\Mvc\Middleware\MiddlewareResult; |
14 | use PeServer\Core\Regex; |
15 | use PeServer\Core\Web\WebSecurity; |
16 | use PeServer\Core\Throws\NotImplementedException; |
17 | |
18 | /** |
19 | * HTTPS 遷移ミドルウェア。 |
20 | */ |
21 | class HttpsMiddleware implements IMiddleware |
22 | { |
23 | public function __construct( |
24 | private ILogger $logger, |
25 | ) { |
26 | } |
27 | |
28 | #region IMiddleware |
29 | |
30 | public function handleBefore(MiddlewareArgument $argument): MiddlewareResult |
31 | { |
32 | if (!$argument->stores->special->isHttps()) { |
33 | $originUrl = $argument->stores->special->getRequestUrl(); |
34 | $httpsUrl = $originUrl->changeScheme('https'); |
35 | $this->logger->info('[REDIRECT] HTTP -> HTTPS'); |
36 | return MiddlewareResult::redirect($httpsUrl); |
37 | } |
38 | |
39 | return MiddlewareResult::none(); |
40 | } |
41 | |
42 | final public function handleAfter(MiddlewareArgument $argument, HttpResponse $response): MiddlewareResult |
43 | { |
44 | return MiddlewareResult::none(); |
45 | } |
46 | |
47 | #endregion |
48 | } |