-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
DebugStack.php
69 lines (55 loc) · 1.6 KB
/
DebugStack.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace DoctrineMongoODMModule\Logging;
use Doctrine\ODM\MongoDB\APM\CommandLoggerInterface;
use MongoDB\Driver\Monitoring\CommandFailedEvent;
use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
use function MongoDB\Driver\Monitoring\addSubscriber;
use function MongoDB\Driver\Monitoring\removeSubscriber;
/**
* Includes executed queries in a Debug Stack
*
* @link www.doctrine-project.org
*/
class DebugStack implements CommandLoggerInterface
{
/** @var mixed[] $queries Executed queries. */
public $queries = [];
/** @var bool $enabled If Debug Stack is enabled (log queries) or not. */
public $enabled = true;
/** @var mixed $currentQuery */
protected $currentQuery = 0;
public function __construct()
{
$this->register();
}
public function register(): void
{
addSubscriber($this);
$this->enabled = true;
}
public function unregister(): void
{
removeSubscriber($this);
$this->enabled = false;
}
public function commandStarted(CommandStartedEvent $event): void
{
if (! $this->enabled) {
return;
}
$this->queries[++$this->currentQuery] = [
'command' => $event->getCommand(),
'db' => $event->getDatabaseName(),
];
}
public function commandSucceeded(CommandSucceededEvent $event): void
{
// currently not being logged
}
public function commandFailed(CommandFailedEvent $event): void
{
// currently not being logged
}
}