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
DevelopmentMiddleware
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\Core\Environment;
8use PeServer\Core\Http\HttpResponse;
9use PeServer\Core\Http\HttpStatus;
10use PeServer\Core\Log\ILogger;
11use PeServer\Core\Mvc\Middleware\IMiddleware;
12use PeServer\Core\Mvc\Middleware\MiddlewareArgument;
13use PeServer\Core\Mvc\Middleware\MiddlewareResult;
14
15final class DevelopmentMiddleware implements IMiddleware
16{
17    public function __construct(
18        private ILogger $logger
19    ) {
20    }
21
22    //[IMiddleware]
23
24    public function handleBefore(MiddlewareArgument $argument): MiddlewareResult
25    {
26        if ($argument->environment->isProduction()) {
27            $this->logger->warn('本番環境での実行は抑制');
28            return MiddlewareResult::error(HttpStatus::Forbidden);
29        }
30
31        return MiddlewareResult::none();
32    }
33
34    public function handleAfter(MiddlewareArgument $argument, HttpResponse $response): MiddlewareResult
35    {
36        return MiddlewareResult::none();
37    }
38}