1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Neo4j\Neo4jBundle\Collector; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
8
|
|
|
use Symfony\Component\HttpFoundation\Response; |
9
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Xavier Coureau <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
final class Neo4jDataCollector extends DataCollector |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var QueryLogger |
18
|
|
|
*/ |
19
|
|
|
private $queryLogger; |
20
|
|
|
|
21
|
|
|
public function __construct(QueryLogger $logger) |
22
|
|
|
{ |
23
|
|
|
$this->queryLogger = $logger; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
30
|
|
|
{ |
31
|
|
|
$this->data['time'] = $this->queryLogger->getElapsedTime(); |
32
|
|
|
$this->data['nb_queries'] = count($this->queryLogger); |
33
|
|
|
$this->data['statements'] = $this->queryLogger->getStatements(); |
34
|
|
|
$this->data['failed_statements'] = array_filter($this->queryLogger->getStatements(), function ($statement) { |
35
|
|
|
return !$statement['success']; |
36
|
|
|
}); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return int |
41
|
|
|
*/ |
42
|
|
|
public function getQueryCount() |
43
|
|
|
{ |
44
|
|
|
return $this->data['nb_queries']; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Return all statements, successful and not successful. |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function getStatements() |
53
|
|
|
{ |
54
|
|
|
return $this->data['statements']; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Return not successful statements. |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function getFailedStatements() |
63
|
|
|
{ |
64
|
|
|
return $this->data['failed_statements']; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return float |
69
|
|
|
*/ |
70
|
|
|
public function getTime() |
71
|
|
|
{ |
72
|
|
|
return $this->data['time']; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return float |
77
|
|
|
*/ |
78
|
|
|
public function getTimeForQuery() |
79
|
|
|
{ |
80
|
|
|
return $this->data['time']; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function getName() |
87
|
|
|
{ |
88
|
|
|
return 'neo4j'; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|