1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Neo4j\Neo4jBundle\EventSubscriber; |
6
|
|
|
|
7
|
|
|
use GraphAware\Neo4j\Client\Event\FailureEvent; |
8
|
|
|
use GraphAware\Neo4j\Client\Event\PostRunEvent; |
9
|
|
|
use GraphAware\Neo4j\Client\Event\PreRunEvent; |
10
|
|
|
use GraphAware\Neo4j\Client\Neo4jClientEvents; |
11
|
|
|
use Neo4j\Neo4jBundle\Collector\QueryLogger; |
12
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
13
|
|
|
|
14
|
|
|
class LoggerSubscriber implements EventSubscriberInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var QueryLogger |
18
|
|
|
*/ |
19
|
|
|
private $queryLogger; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param QueryLogger $queryLogger |
23
|
|
|
*/ |
24
|
|
|
public function __construct(QueryLogger $queryLogger) |
25
|
|
|
{ |
26
|
|
|
$this->queryLogger = $queryLogger; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
1 |
|
public static function getSubscribedEvents() |
33
|
|
|
{ |
34
|
|
|
return [ |
35
|
1 |
|
Neo4jClientEvents::NEO4J_PRE_RUN => 'onPreRun', |
36
|
1 |
|
Neo4jClientEvents::NEO4J_POST_RUN => 'onPostRun', |
37
|
1 |
|
Neo4jClientEvents::NEO4J_ON_FAILURE => 'onFailure', |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param PreRunEvent $event |
43
|
|
|
*/ |
44
|
|
|
public function onPreRun(PreRunEvent $event) |
45
|
|
|
{ |
46
|
|
|
foreach ($event->getStatements() as $statement) { |
47
|
|
|
$this->queryLogger->record($statement); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param PostRunEvent $event |
53
|
|
|
*/ |
54
|
|
|
public function onPostRun(PostRunEvent $event) |
55
|
|
|
{ |
56
|
|
|
foreach ($event->getResults() as $result) { |
57
|
|
|
$this->queryLogger->finish($result); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param FailureEvent $event |
63
|
|
|
*/ |
64
|
|
|
public function onFailure(FailureEvent $event) |
65
|
|
|
{ |
66
|
|
|
$this->queryLogger->logException($event->getException()); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|