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 | * Sets IO. |
||
64 | * |
||
65 | * @param ConsoleIO $io Console IO. |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | 3 | public function setIO(ConsoleIO $io = null) |
|
74 | |||
75 | /** |
||
76 | * Adds statement to ignore list. |
||
77 | * |
||
78 | * @param string $statement The SQL query statement. |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | 5 | public function ignoreDuplicateStatement($statement) |
|
86 | |||
87 | /** |
||
88 | * Turns the profiler on and off. |
||
89 | * |
||
90 | * @param boolean $active True to turn on, false to turn off. |
||
91 | * |
||
92 | * @return void |
||
93 | */ |
||
94 | 18 | public function setActive($active) |
|
98 | |||
99 | /** |
||
100 | * Is the profiler active? |
||
101 | * |
||
102 | * @return boolean |
||
103 | */ |
||
104 | 19 | public function isActive() |
|
108 | |||
109 | /** |
||
110 | * Toggle duplicate statement tracker. |
||
111 | * |
||
112 | * @param boolean $track Duplicate statement tracker status. |
||
113 | * |
||
114 | * @return void |
||
115 | */ |
||
116 | 8 | public function trackDuplicates($track) |
|
120 | |||
121 | /** |
||
122 | * Adds a profile entry. |
||
123 | * |
||
124 | * @param float $duration The query duration. |
||
125 | * @param string $function The PDO method that made the entry. |
||
126 | * @param string $statement The SQL query statement. |
||
127 | * @param array $bind_values The values bound to the statement. |
||
128 | * |
||
129 | * @return void |
||
130 | * @throws \PDOException When duplicate statement is detected. |
||
131 | */ |
||
132 | 17 | public function addProfile( |
|
171 | |||
172 | /** |
||
173 | * Removes a profile entry. |
||
174 | * |
||
175 | * @param string $statement The SQL query statement. |
||
176 | * @param array $bind_values The values bound to the statement. |
||
177 | * |
||
178 | * @return void |
||
179 | */ |
||
180 | 2 | public function removeProfile($statement, array $bind_values = array()) |
|
189 | |||
190 | /** |
||
191 | * Normalizes statement. |
||
192 | * |
||
193 | * @param string $statement The SQL query statement. |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | 15 | protected function normalizeStatement($statement) |
|
201 | |||
202 | /** |
||
203 | * Creates profile key. |
||
204 | * |
||
205 | * @param string $normalized_statement The normalized SQL query statement. |
||
206 | * @param array $bind_values The values bound to the statement. |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | 14 | protected function createProfileKey($normalized_statement, array $bind_values = array()) |
|
214 | |||
215 | /** |
||
216 | * Substitutes parameters in the statement. |
||
217 | * |
||
218 | * @param string $normalized_statement The normalized SQL query statement. |
||
219 | * @param array $bind_values The values bound to the statement. |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | 2 | protected function substituteParameters($normalized_statement, array $bind_values = array()) |
|
240 | |||
241 | /** |
||
242 | * Returns all the profile entries. |
||
243 | * |
||
244 | * @return array |
||
245 | */ |
||
246 | 13 | public function getProfiles() |
|
250 | |||
251 | /** |
||
252 | * Reset all the profiles |
||
253 | * |
||
254 | * @return void |
||
255 | */ |
||
256 | 1 | public function resetProfiles() |
|
260 | |||
261 | } |
||
262 |