1 | <?php declare(strict_types = 1); |
||
15 | final class MongoDbDataCollector extends DataCollector |
||
16 | { |
||
17 | const QUERY_KEYWORD = 'queries'; |
||
18 | const CONNECTION_KEYWORD = 'connections'; |
||
19 | const TIME_KEYWORD = 'totalTime'; |
||
20 | |||
21 | /** @var DataCollectorLoggerInterface */ |
||
22 | private $logger; |
||
23 | |||
24 | 1 | public function __construct() |
|
32 | |||
33 | /** |
||
34 | * @param DataCollectorLoggerInterface $logger |
||
35 | */ |
||
36 | 1 | public function setLogger(DataCollectorLoggerInterface $logger) |
|
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | 1 | public function collect(Request $request, Response $response, \Exception $exception = null) |
|
45 | { |
||
46 | 1 | while ($this->logger->hasLoggedEvents()) { |
|
47 | /** @var Query $event */ |
||
48 | 1 | $event = $this->logger->getLoggedEvent(); |
|
49 | |||
50 | // with extension version under 1.2.4 some Mongo objects can't be automatically serialized |
||
51 | 1 | if (-1 === version_compare(phpversion('mongodb'), '1.2.4')) { |
|
52 | 1 | MongoQuerySerializer::serialize($event); |
|
53 | } |
||
54 | |||
55 | 1 | $this->data[self::QUERY_KEYWORD][] = $event; |
|
56 | 1 | $this->data[self::TIME_KEYWORD] += $event->getExecutionTime(); |
|
57 | } |
||
58 | |||
59 | 1 | $this->data[self::CONNECTION_KEYWORD] = $this->logger->getConnections(); |
|
60 | 1 | } |
|
61 | |||
62 | /** |
||
63 | * @return int |
||
64 | */ |
||
65 | 1 | public function getQueryCount(): int |
|
69 | |||
70 | /** |
||
71 | * @return array |
||
72 | */ |
||
73 | 1 | public function getQueries(): array |
|
77 | |||
78 | /** |
||
79 | * @return float |
||
80 | */ |
||
81 | 1 | public function getTime(): float |
|
85 | |||
86 | /** |
||
87 | * @return int |
||
88 | */ |
||
89 | 1 | public function getConnectionsCount(): int |
|
93 | /** |
||
94 | * @return array|string[] |
||
95 | */ |
||
96 | 1 | public function getConnections(): array |
|
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | 1 | public function getName() |
|
108 | } |
||
109 |