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\DataCollector; |
14
|
|
|
|
15
|
|
|
use Fresh\CentrifugoBundle\Logger\CommandHistoryLogger; |
16
|
|
|
use Fresh\CentrifugoBundle\Model\CommandInterface; |
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
19
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* CentrifugoCollector. |
23
|
|
|
* |
24
|
|
|
* @author Artem Henvald <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class CentrifugoCollector extends DataCollector |
27
|
|
|
{ |
28
|
|
|
/** @var CommandHistoryLogger */ |
29
|
|
|
private $centrifugoLogger; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param CommandHistoryLogger $commandHistoryLogger |
33
|
|
|
*/ |
34
|
|
|
public function __construct(CommandHistoryLogger $commandHistoryLogger) |
35
|
|
|
{ |
36
|
|
|
$this->centrifugoLogger = $commandHistoryLogger; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function collect(Request $request, Response $response, \Throwable $exception = null): void |
43
|
|
|
{ |
44
|
|
|
$this->data = $this->centrifugoLogger->getCommandHistory(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function getName(): string |
51
|
|
|
{ |
52
|
|
|
return 'centrifugo'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function reset(): void |
59
|
|
|
{ |
60
|
|
|
$this->data = []; |
61
|
|
|
$this->centrifugoLogger->clearCommandHistory(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return int |
66
|
|
|
*/ |
67
|
|
|
public function getCommandCount(): int |
68
|
|
|
{ |
69
|
|
|
return \count($this->data); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return int |
74
|
|
|
*/ |
75
|
|
|
public function getRequestCount(): int |
76
|
|
|
{ |
77
|
|
|
return \count($this->data); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return CommandInterface[] |
82
|
|
|
*/ |
83
|
|
|
public function getCommands(): array |
84
|
|
|
{ |
85
|
|
|
return $this->data; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|