-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProfiler.php
More file actions
50 lines (38 loc) · 981 Bytes
/
Profiler.php
File metadata and controls
50 lines (38 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace UniMapper;
class Profiler
{
private static $captured = [];
private static $enabled = false;
private static $query;
private static $results = [];
public static function startQuery(Query $query)
{
self::flush();
self::$query = $query;
self::$enabled = true;
}
public static function log(Adapter\IQuery $query, $result)
{
if (self::$query) {
self::$captured[] = $query->getRaw();
} else {
new Profiler\Result([$query->getRaw()]);
}
}
public static function endQuery($result, $elapsed)
{
self::$results[] = new Profiler\Result(self::$captured, $elapsed, $result, self::$query);
self::flush();
self::$enabled = false;
}
public static function flush()
{
self::$captured = [];
self::$query = null;
}
public static function getResults()
{
return self::$results;
}
}