|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace DoctrineORMModule\Collector; |
|
21
|
|
|
|
|
22
|
|
|
use ZendDeveloperTools\Collector\CollectorInterface; |
|
23
|
|
|
use ZendDeveloperTools\Collector\AutoHideInterface; |
|
24
|
|
|
|
|
25
|
|
|
use Zend\Mvc\MvcEvent; |
|
26
|
|
|
|
|
27
|
|
|
use Doctrine\DBAL\Logging\DebugStack; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Collector to be used in ZendDeveloperTools to record and display SQL queries |
|
31
|
|
|
* |
|
32
|
|
|
* @license MIT |
|
33
|
|
|
* @link www.doctrine-project.org |
|
34
|
|
|
* @author Marco Pivetta <[email protected]> |
|
35
|
|
|
*/ |
|
36
|
|
|
class SQLLoggerCollector implements CollectorInterface, AutoHideInterface |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* Collector priority |
|
40
|
|
|
*/ |
|
41
|
|
|
const PRIORITY = 10; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var DebugStack |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $sqlLogger; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $name; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param DebugStack $sqlLogger |
|
55
|
|
|
* @param string $name |
|
56
|
|
|
*/ |
|
57
|
11 |
|
public function __construct(DebugStack $sqlLogger, $name) |
|
58
|
|
|
{ |
|
59
|
11 |
|
$this->sqlLogger = $sqlLogger; |
|
60
|
11 |
|
$this->name = (string) $name; |
|
61
|
11 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritDoc} |
|
65
|
|
|
*/ |
|
66
|
2 |
|
public function getName() |
|
67
|
|
|
{ |
|
68
|
2 |
|
return $this->name; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritDoc} |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function getPriority() |
|
75
|
|
|
{ |
|
76
|
1 |
|
return static::PRIORITY; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritDoc} |
|
81
|
|
|
*/ |
|
82
|
1 |
|
public function collect(MvcEvent $mvcEvent) |
|
83
|
|
|
{ |
|
84
|
1 |
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* {@inheritDoc} |
|
88
|
|
|
*/ |
|
89
|
1 |
|
public function canHide() |
|
90
|
|
|
{ |
|
91
|
1 |
|
return empty($this->sqlLogger->queries); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return int |
|
96
|
|
|
*/ |
|
97
|
1 |
|
public function getQueryCount() |
|
98
|
|
|
{ |
|
99
|
1 |
|
return count($this->sqlLogger->queries); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getQueries() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->sqlLogger->queries; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return float |
|
112
|
|
|
*/ |
|
113
|
1 |
|
public function getQueryTime() |
|
114
|
|
|
{ |
|
115
|
1 |
|
$time = 0.0; |
|
116
|
|
|
|
|
117
|
1 |
|
foreach ($this->sqlLogger->queries as $query) { |
|
118
|
1 |
|
$time += $query['executionMS']; |
|
119
|
1 |
|
} |
|
120
|
|
|
|
|
121
|
1 |
|
return $time; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|