1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @codingStandardsIgnoreStart |
4
|
|
|
* |
5
|
|
|
* @author Barney Hanlon <[email protected]> |
6
|
|
|
* @copyright Barney Hanlon 2017 |
7
|
|
|
* @license https://opensource.org/licenses/MIT |
8
|
|
|
* |
9
|
|
|
* @codingStandardsIgnoreEnd |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Shrikeh\GuzzleMiddleware\TimerLogger\Formatter\Message; |
13
|
|
|
|
14
|
|
|
use Psr\Http\Message\RequestInterface; |
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
16
|
|
|
use Shrikeh\GuzzleMiddleware\TimerLogger\Timer\TimerInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class DefaultStopMessage. |
20
|
|
|
*/ |
21
|
|
|
final class DefaultStopMessage |
22
|
|
|
{ |
23
|
|
|
const MSG = 'Completed call to %s in %dms with response code %d'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param TimerInterface $timer The timer to format for the log |
27
|
|
|
* @param RequestInterface $request The Request to format for the log |
28
|
|
|
* @param ResponseInterface $response The Response to format for the log |
29
|
|
|
* |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
public function __invoke( |
33
|
|
|
TimerInterface $timer, |
34
|
|
|
RequestInterface $request, |
35
|
|
|
ResponseInterface $response |
36
|
|
|
) { |
37
|
|
|
return $this->stopMessage($timer, $request, $response); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param TimerInterface $timer The timer to format for the log |
42
|
|
|
* @param RequestInterface $request The Request to format for the log |
43
|
|
|
* @param ResponseInterface $response The Response to format for the log |
44
|
|
|
* |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public function stopMessage( |
48
|
|
|
TimerInterface $timer, |
49
|
|
|
RequestInterface $request, |
50
|
|
|
ResponseInterface $response |
51
|
|
|
) { |
52
|
|
|
return \sprintf( |
53
|
|
|
self::MSG, |
54
|
|
|
$request->getUri(), |
55
|
|
|
$timer->duration(), |
56
|
|
|
$response->getStatusCode() |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|