|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the FreshCentrifugoBundle. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Artem Henvald <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace Fresh\CentrifugoBundle\Logger; |
|
14
|
|
|
|
|
15
|
|
|
use Fresh\CentrifugoBundle\Model\CommandInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* CommandHistoryLogger. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Artem Henvald <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class CommandHistoryLogger |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var array */ |
|
25
|
|
|
private $commandHistory = []; |
|
26
|
|
|
|
|
27
|
|
|
/** @var int */ |
|
28
|
|
|
private $requestsCount = 0; |
|
29
|
|
|
|
|
30
|
|
|
/** @var int */ |
|
31
|
|
|
private $commandsCount = 0; |
|
32
|
|
|
|
|
33
|
|
|
/** @var int */ |
|
34
|
|
|
private $successfulCommandsCount = 0; |
|
35
|
|
|
|
|
36
|
|
|
/** @var int */ |
|
37
|
|
|
private $failedCommandsCount = 0; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param CommandInterface $command |
|
41
|
|
|
* @param bool $success |
|
42
|
|
|
* @param array|null $result |
|
43
|
|
|
*/ |
|
44
|
|
|
public function logCommand(CommandInterface $command, bool $success, ?array $result): void |
|
45
|
|
|
{ |
|
46
|
|
|
$this->commandHistory[] = [ |
|
47
|
|
|
'command' => $command, |
|
48
|
|
|
'result' => $result, |
|
49
|
|
|
'success' => $success, |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
++$this->commandsCount; |
|
53
|
|
|
|
|
54
|
|
|
if ($success) { |
|
55
|
|
|
++$this->successfulCommandsCount; |
|
56
|
|
|
} else { |
|
57
|
|
|
++$this->failedCommandsCount; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Clear command history. |
|
63
|
|
|
*/ |
|
64
|
|
|
public function clearCommandHistory(): void |
|
65
|
|
|
{ |
|
66
|
|
|
$this->commandHistory = []; |
|
67
|
|
|
$this->requestsCount = 0; |
|
68
|
|
|
$this->commandsCount = 0; |
|
69
|
|
|
$this->successfulCommandsCount = 0; |
|
70
|
|
|
$this->failedCommandsCount = 0; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return CommandInterface[] |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getCommandHistory(): array |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->commandHistory; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Increase requests count. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function increaseRequestsCount(): void |
|
85
|
|
|
{ |
|
86
|
|
|
++$this->requestsCount; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return int |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getRequestsCount(): int |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->requestsCount; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return int |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getCommandsCount(): int |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->commandsCount; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return int |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getSuccessfulCommandsCount(): int |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->successfulCommandsCount; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return int |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getFailedCommandsCount(): int |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->failedCommandsCount; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|