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
|
|
|
private array $commandHistory = []; |
|
|
|
|
25
|
|
|
private int $requestsCount = 0; |
26
|
|
|
private int $commandsCount = 0; |
27
|
|
|
private int $successfulCommandsCount = 0; |
28
|
|
|
private int $failedCommandsCount = 0; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param CommandInterface $command |
32
|
|
|
* @param bool $success |
33
|
|
|
* @param array|null $result |
34
|
|
|
*/ |
35
|
|
|
public function logCommand(CommandInterface $command, bool $success, ?array $result): void |
36
|
|
|
{ |
37
|
|
|
$this->commandHistory[] = [ |
38
|
|
|
'command' => $command, |
39
|
|
|
'result' => $result, |
40
|
|
|
'success' => $success, |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
++$this->commandsCount; |
44
|
|
|
|
45
|
|
|
if ($success) { |
46
|
|
|
++$this->successfulCommandsCount; |
47
|
|
|
} else { |
48
|
|
|
++$this->failedCommandsCount; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Clear command history. |
54
|
|
|
*/ |
55
|
|
|
public function clearCommandHistory(): void |
56
|
|
|
{ |
57
|
|
|
$this->commandHistory = []; |
58
|
|
|
$this->requestsCount = 0; |
59
|
|
|
$this->commandsCount = 0; |
60
|
|
|
$this->successfulCommandsCount = 0; |
61
|
|
|
$this->failedCommandsCount = 0; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return CommandInterface[] |
66
|
|
|
*/ |
67
|
|
|
public function getCommandHistory(): array |
68
|
|
|
{ |
69
|
|
|
return $this->commandHistory; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Increase requests count. |
74
|
|
|
*/ |
75
|
|
|
public function increaseRequestsCount(): void |
76
|
|
|
{ |
77
|
|
|
++$this->requestsCount; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return int |
82
|
|
|
*/ |
83
|
|
|
public function getRequestsCount(): int |
84
|
|
|
{ |
85
|
|
|
return $this->requestsCount; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return int |
90
|
|
|
*/ |
91
|
|
|
public function getCommandsCount(): int |
92
|
|
|
{ |
93
|
|
|
return $this->commandsCount; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return int |
98
|
|
|
*/ |
99
|
|
|
public function getSuccessfulCommandsCount(): int |
100
|
|
|
{ |
101
|
|
|
return $this->successfulCommandsCount; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return int |
106
|
|
|
*/ |
107
|
|
|
public function getFailedCommandsCount(): int |
108
|
|
|
{ |
109
|
|
|
return $this->failedCommandsCount; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|