Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PerformanceMiddleware | |
0.00% |
0 / 6 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handleBefore | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
handleAfter | |
0.00% |
0 / 3 |
|
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\Http\HttpResponse; |
8 | use PeServer\Core\Log\ILogger; |
9 | use PeServer\Core\Mvc\Middleware\MiddlewareArgument; |
10 | use PeServer\Core\Mvc\Middleware\MiddlewareResult; |
11 | |
12 | /** |
13 | * ある区間からの測定処理。 |
14 | * |
15 | * グローバルに登録すれば全体、アクションに登録すればアクションの時間測定。 |
16 | * 別にそこまで厳密なものじゃないので `hrtime` は使用していない。 |
17 | */ |
18 | final class PerformanceMiddleware implements IMiddleware |
19 | { |
20 | #region variable |
21 | |
22 | private float $beforeMsec; |
23 | |
24 | #endregion |
25 | |
26 | public function __construct( |
27 | private ILogger $logger |
28 | ) { |
29 | } |
30 | |
31 | #region IMiddleware |
32 | |
33 | public function handleBefore(MiddlewareArgument $argument): MiddlewareResult |
34 | { |
35 | $this->beforeMsec = microtime(true); |
36 | |
37 | return MiddlewareResult::none(); |
38 | } |
39 | |
40 | public function handleAfter(MiddlewareArgument $argument, HttpResponse $response): MiddlewareResult |
41 | { |
42 | $afterMsec = microtime(true); |
43 | |
44 | $this->logger->info('action {0} ms', $afterMsec - $this->beforeMsec); |
45 | |
46 | return MiddlewareResult::none(); |
47 | } |
48 | |
49 | #endregion |
50 | } |