-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoctrineMetric.php
41 lines (30 loc) · 1002 Bytes
/
DoctrineMetric.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace Odandb\MonitoringMetricsBundle\Metric;
use Doctrine\DBAL\Logging\DebugStack;
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
use Symfony\Component\HttpFoundation\Response;
class DoctrineMetric extends AbstractMetric
{
public const HEADER_NAME = 'X-Monitor-Doctrine-Queries';
protected DebugDataHolder $debugDataHolder;
public function __construct(DebugDataHolder $debugDataHolder)
{
$this->debugDataHolder = $debugDataHolder;
}
public function metric(Response $response): void
{
$queries = [];
foreach ($this->debugDataHolder->getData() as $name => $data) {
if (!isset($queries[$name])) {
$queries[$name] = 0;
}
$queries[$name] += count($data);
}
$response->headers->set(self::HEADER_NAME, (string) array_sum($queries));
}
public function reset(): void
{
$this->debugDataHolder->reset();
}
}