Total Complexity | 7 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
7 | class ApiLogger implements ApiInterface |
||
8 | { |
||
9 | /** |
||
10 | * @var LoggerInterface |
||
11 | */ |
||
12 | protected $logger; |
||
13 | |||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $calls = []; |
||
18 | |||
19 | /** |
||
20 | * @var bool |
||
21 | */ |
||
22 | protected $debug = false; |
||
23 | |||
24 | |||
25 | 2 | public function __construct(LoggerInterface $logger = null, $debug = false) |
|
29 | 2 | } |
|
30 | |||
31 | 1 | public function logCall($host, $path, $method, $time, array $requestHeaders = [], array $params = [], array $responseHeaders = [], $result = null) |
|
32 | { |
||
33 | 1 | if($this->debug) |
|
34 | { |
||
35 | 1 | $this->calls[] = [ |
|
36 | 1 | 'host' => $host, |
|
37 | 1 | 'path' => $path, |
|
38 | 1 | 'method' => $method, |
|
39 | 1 | 'time' => $time, |
|
40 | 1 | 'request_headers' => $requestHeaders, |
|
41 | 1 | 'params' => $params, |
|
42 | 1 | 'response_headers' => $responseHeaders, |
|
43 | 1 | 'result' => $result |
|
44 | ]; |
||
45 | } |
||
46 | |||
47 | 1 | if(null !== $this->logger) |
|
48 | { |
||
49 | 1 | $this->logger->info(sprintf("%s (%s) %0.2f ms, params: %s", $path, $method, $time * 1000, json_encode($params))); |
|
50 | } |
||
51 | 1 | } |
|
52 | |||
53 | 1 | public function getCalls() |
|
54 | { |
||
55 | 1 | return $this->calls; |
|
56 | } |
||
57 | |||
58 | 1 | public function getCallsCount() |
|
61 | } |
||
62 | } |