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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Doctrine\DBAL\Logging;
use function microtime;
/**
* Includes executed SQLs in a Debug Stack.
*/
class DebugStack implements SQLLogger
{
/**
* Executed SQL queries.
*
* @var mixed[][]
*/
public $queries = [];
/**
* If Debug Stack is enabled (log queries) or not.
*
* @var bool
*/
public $enabled = true;
/** @var float|null */
public $start = null;
/** @var int */
public $currentQuery = 0;
/**
* {@inheritdoc}
*/
public function startQuery($sql, ?array $params = null, ?array $types = null)
{
if (! $this->enabled) {
return;
}
$this->start = microtime(true);
$this->queries[++$this->currentQuery] = ['sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0];
}
/**
* {@inheritdoc}
*/
public function stopQuery()
{
if (! $this->enabled) {
return;
}
$this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
}
}