|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - |
|
4
|
|
|
|
|
5
|
|
|
Title : PHP Quick Profiler Console Class |
|
6
|
|
|
Author : Created by Ryan Campbell |
|
7
|
|
|
URL : http://particletree.com/features/php-quick-profiler/ |
|
8
|
|
|
|
|
9
|
|
|
Last Updated : April 22, 2009 |
|
10
|
|
|
|
|
11
|
|
|
Description : This class serves as a wrapper around a global |
|
12
|
|
|
php variable, debugger_logs, that we have created. |
|
13
|
|
|
|
|
14
|
|
|
- - - - - - - - - - - - - - - - - - - - - */ |
|
15
|
|
|
|
|
16
|
|
|
namespace Particletree\Pqp; |
|
17
|
|
|
|
|
18
|
|
|
class Console { |
|
19
|
|
|
|
|
20
|
|
|
/*----------------------------------- |
|
21
|
|
|
LOG A VARIABLE TO CONSOLE |
|
22
|
|
|
------------------------------------*/ |
|
23
|
|
|
|
|
24
|
|
|
public static function log($data) { |
|
|
|
|
|
|
25
|
|
|
$logItem = array( |
|
26
|
|
|
"data" => $data, |
|
27
|
|
|
"type" => 'log' |
|
28
|
|
|
); |
|
29
|
|
|
$GLOBALS['debugger_logs']['console'][] = $logItem; |
|
30
|
|
|
$GLOBALS['debugger_logs']['logCount'] += 1; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/*--------------------------------------------------- |
|
34
|
|
|
LOG MEMORY USAGE OF VARIABLE OR ENTIRE SCRIPT |
|
35
|
|
|
-----------------------------------------------------*/ |
|
36
|
|
|
|
|
37
|
|
|
public function logMemory($object = false, $name = 'PHP') { |
|
|
|
|
|
|
38
|
|
|
$memory = memory_get_usage(); |
|
39
|
|
|
if($object) $memory = strlen(serialize($object)); |
|
40
|
|
|
$logItem = array( |
|
41
|
|
|
"data" => $memory, |
|
42
|
|
|
"type" => 'memory', |
|
43
|
|
|
"name" => $name, |
|
44
|
|
|
"dataType" => gettype($object) |
|
45
|
|
|
); |
|
46
|
|
|
$GLOBALS['debugger_logs']['console'][] = $logItem; |
|
47
|
|
|
$GLOBALS['debugger_logs']['memoryCount'] += 1; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/*----------------------------------- |
|
51
|
|
|
LOG A PHP EXCEPTION OBJECT |
|
52
|
|
|
------------------------------------*/ |
|
53
|
|
|
|
|
54
|
|
|
public function logError($exception, $message) { |
|
|
|
|
|
|
55
|
|
|
$logItem = array( |
|
56
|
|
|
"data" => $message, |
|
57
|
|
|
"type" => 'error', |
|
58
|
|
|
"file" => $exception->getFile(), |
|
59
|
|
|
"line" => $exception->getLine() |
|
60
|
|
|
); |
|
61
|
|
|
$GLOBALS['debugger_logs']['console'][] = $logItem; |
|
62
|
|
|
@$GLOBALS['debugger_logs']['errorCount'] += 1; |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/*------------------------------------ |
|
66
|
|
|
POINT IN TIME SPEED SNAPSHOT |
|
67
|
|
|
-------------------------------------*/ |
|
68
|
|
|
|
|
69
|
|
|
public function logSpeed($name = 'Point in Time') { |
|
|
|
|
|
|
70
|
|
|
$logItem = array( |
|
71
|
|
|
"data" => PhpQuickProfiler::getMicroTime(), |
|
72
|
|
|
"type" => 'speed', |
|
73
|
|
|
"name" => $name |
|
74
|
|
|
); |
|
75
|
|
|
$GLOBALS['debugger_logs']['console'][] = $logItem; |
|
76
|
|
|
$GLOBALS['debugger_logs']['speedCount'] += 1; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/*----------------------------------- |
|
80
|
|
|
SET DEFAULTS & RETURN LOGS |
|
81
|
|
|
------------------------------------*/ |
|
82
|
|
|
|
|
83
|
|
|
public function getLogs() { |
|
|
|
|
|
|
84
|
|
|
if(!$GLOBALS['debugger_logs']['memoryCount']) $GLOBALS['debugger_logs']['memoryCount'] = 0; |
|
85
|
|
|
if(!$GLOBALS['debugger_logs']['logCount']) $GLOBALS['debugger_logs']['logCount'] = 0; |
|
86
|
|
|
if(!$GLOBALS['debugger_logs']['speedCount']) $GLOBALS['debugger_logs']['speedCount'] = 0; |
|
87
|
|
|
if(!$GLOBALS['debugger_logs']['errorCount']) $GLOBALS['debugger_logs']['errorCount'] = 0; |
|
88
|
|
|
return $GLOBALS['debugger_logs']; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
?> |
|
|
|
|
|
|
93
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: