1 | <?php |
||
17 | class StatementProfiler implements ProfilerInterface |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Is the profiler active? |
||
22 | * |
||
23 | * @var boolean |
||
24 | */ |
||
25 | protected $active = false; |
||
26 | |||
27 | /** |
||
28 | * Retained profiles. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $profiles = array(); |
||
33 | |||
34 | /** |
||
35 | * Track duplicate statements. |
||
36 | * |
||
37 | * @var boolean |
||
38 | */ |
||
39 | protected $trackDuplicates = true; |
||
40 | |||
41 | /** |
||
42 | * Ignored duplicate statements. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $ignoredDuplicateStatements = array(); |
||
47 | |||
48 | /** |
||
49 | * Console IO. |
||
50 | * |
||
51 | * @var ConsoleIO |
||
52 | */ |
||
53 | private $_io; |
||
54 | |||
55 | /** |
||
56 | * Debug mode. |
||
57 | * |
||
58 | * @var boolean |
||
59 | */ |
||
60 | private $_debugMode = false; |
||
61 | |||
62 | /** |
||
63 | * Debug backtrace options. |
||
64 | * |
||
65 | * @var integer |
||
66 | */ |
||
67 | private $_backtraceOptions; |
||
68 | |||
69 | 3 | /** |
|
70 | * Creates statement profiler instance. |
||
71 | 3 | */ |
|
72 | 3 | public function __construct() |
|
76 | |||
77 | /** |
||
78 | * Sets IO. |
||
79 | * |
||
80 | * @param ConsoleIO $io Console IO. |
||
81 | * |
||
82 | 116 | * @return void |
|
83 | */ |
||
84 | 116 | public function setIO(ConsoleIO $io = null) |
|
89 | |||
90 | /** |
||
91 | * Adds statement to ignore list. |
||
92 | * |
||
93 | * @param string $statement The SQL query statement. |
||
94 | 130 | * |
|
95 | * @return void |
||
96 | 130 | */ |
|
97 | 130 | public function ignoreDuplicateStatement($statement) |
|
101 | |||
102 | /** |
||
103 | * Turns the profiler on and off. |
||
104 | 118 | * |
|
105 | * @param boolean $active True to turn on, false to turn off. |
||
106 | 118 | * |
|
107 | * @return void |
||
108 | */ |
||
109 | public function setActive($active) |
||
113 | |||
114 | /** |
||
115 | * Is the profiler active? |
||
116 | 9 | * |
|
117 | * @return boolean |
||
118 | 9 | */ |
|
119 | 9 | public function isActive() |
|
123 | |||
124 | /** |
||
125 | * Toggle duplicate statement tracker. |
||
126 | * |
||
127 | * @param boolean $track Duplicate statement tracker status. |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | public function trackDuplicates($track) |
||
135 | |||
136 | /** |
||
137 | * Adds a profile entry. |
||
138 | 116 | * |
|
139 | 102 | * @param float $duration The query duration. |
|
140 | * @param string $function The PDO method that made the entry. |
||
141 | * @param string $statement The SQL query statement. |
||
142 | 113 | * @param array $bind_values The values bound to the statement. |
|
143 | 113 | * |
|
144 | * @return void |
||
145 | 113 | * @throws \PDOException When duplicate statement is detected. |
|
146 | 113 | */ |
|
147 | 113 | public function addProfile( |
|
194 | |||
195 | /** |
||
196 | * Removes a profile entry. |
||
197 | 127 | * |
|
198 | * @param string $statement The SQL query statement. |
||
199 | 127 | * @param array $bind_values The values bound to the statement. |
|
200 | * |
||
201 | * @return void |
||
202 | */ |
||
203 | public function removeProfile($statement, array $bind_values = array()) |
||
212 | 113 | ||
213 | /** |
||
214 | * Normalizes statement. |
||
215 | * |
||
216 | * @param string $statement The SQL query statement. |
||
217 | * |
||
218 | * @return string |
||
219 | */ |
||
220 | protected function normalizeStatement($statement) |
||
224 | |||
225 | 4 | /** |
|
226 | * Creates profile key. |
||
227 | 4 | * |
|
228 | 4 | * @param string $normalized_statement The normalized SQL query statement. |
|
229 | 1 | * @param array $bind_values The values bound to the statement. |
|
230 | 1 | * |
|
231 | * @return string |
||
232 | 4 | */ |
|
233 | protected function createProfileKey($normalized_statement, array $bind_values = array()) |
||
237 | |||
238 | 4 | /** |
|
239 | * Substitutes parameters in the statement. |
||
240 | * |
||
241 | * @param string $normalized_statement The normalized SQL query statement. |
||
242 | * @param array $bind_values The values bound to the statement. |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | 14 | protected function substituteParameters($normalized_statement, array $bind_values = array()) |
|
263 | |||
264 | /** |
||
265 | * Returns all the profile entries. |
||
266 | * |
||
267 | * @return array |
||
268 | */ |
||
269 | public function getProfiles() |
||
273 | |||
274 | /** |
||
275 | * Reset all the profiles |
||
276 | * |
||
277 | * @return void |
||
278 | */ |
||
279 | public function resetProfiles() |
||
283 | |||
284 | } |
||
285 |