1
|
|
|
<?
|
|
|
|
|
2
|
|
|
|
3
|
|
|
use Particletree\Pqp\Console;
|
|
|
|
|
4
|
|
|
use Particletree\Pqp\PhpQuickProfiler;
|
|
|
|
|
5
|
|
|
|
6
|
|
|
final class Debugger
|
7
|
|
|
{
|
8
|
|
|
|
9
|
|
|
private static $UNKNOWN_ERROR_FILE = 'Unknown File';
|
10
|
|
|
private static $UNKNOWN_ERROR_LINE = 'Unknown Line';
|
11
|
|
|
private static $UNKNOWN_ERROR_CONTEXT = 'Unknown Context';
|
12
|
|
|
|
13
|
|
|
private $profiler;
|
14
|
|
|
private $display = true;
|
|
|
|
|
15
|
|
|
|
16
|
|
|
private static $instance;
|
17
|
|
|
|
18
|
|
|
private function __construct()
|
19
|
|
|
{
|
20
|
|
|
$this->console = new Console();
|
|
|
|
|
21
|
|
|
$this->profiler = new PhpQuickProfiler();
|
22
|
|
|
$this->profiler->setConsole($this->console);
|
23
|
|
|
}
|
24
|
|
|
|
25
|
|
|
public static function instance()
|
26
|
|
|
{
|
27
|
|
|
if(!isset(self::$instance))
|
28
|
|
|
self::$instance = new Debugger();
|
29
|
|
|
return self::$instance;
|
30
|
|
|
}
|
31
|
|
|
|
32
|
|
|
public static function log($message)
|
33
|
|
|
{
|
34
|
|
|
self::instance()->console->logError(new Exception(), 'Gah, this is using Debugger::log()!');
|
35
|
|
|
self::instance()->console->log($message);
|
36
|
|
|
}
|
37
|
|
|
|
38
|
|
|
public static function logMessage($message)
|
39
|
|
|
{
|
40
|
|
|
self::instance()->console->log($message);
|
41
|
|
|
}
|
42
|
|
|
|
43
|
|
|
public static function logMemory($object = null, $name = '')
|
44
|
|
|
{
|
45
|
|
|
self::instance()->console->logMemory($object, $name);
|
46
|
|
|
}
|
47
|
|
|
|
48
|
|
|
public static function logSpeed($message = '')
|
49
|
|
|
{
|
50
|
|
|
self::instance()->console->logSpeed($message);
|
51
|
|
|
}
|
52
|
|
|
|
53
|
|
|
public static function internal_error($code, $string, $file = null, $line = null, $context = null)
|
54
|
|
|
{
|
55
|
|
|
if($file == null)
|
56
|
|
|
$file = self::$UNKNOWN_ERROR_FILE;
|
|
|
|
|
57
|
|
|
if($line == null)
|
58
|
|
|
$line = self::$UNKNOWN_ERROR_LINE;
|
|
|
|
|
59
|
|
|
if($context == null)
|
60
|
|
|
$context = self::$UNKNOWN_ERROR_CONTEXT;
|
|
|
|
|
61
|
|
|
|
62
|
|
|
self::instance()->console->logError(new Exception($string), "{$string}... TYPE: {$code}");
|
63
|
|
|
|
64
|
|
|
return true;
|
65
|
|
|
}
|
66
|
|
|
|
67
|
|
|
public static function shutdown()
|
68
|
|
|
{
|
69
|
|
|
$error = error_get_last();
|
70
|
|
|
|
71
|
|
|
if(isset($error))
|
72
|
|
|
self::internal_error($error['type'], $error['message'], $error['file'], $error['line']);
|
73
|
|
|
|
74
|
|
|
self::display();
|
75
|
|
|
return true;
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
public static function hide()
|
79
|
|
|
{
|
80
|
|
|
self::instance()->display = false;
|
81
|
|
|
}
|
82
|
|
|
|
83
|
|
|
public static function display()
|
|
|
|
|
84
|
|
|
{
|
85
|
|
|
if ($_COOKIE['debugger'] == 'display' && self::instance()->display) {
|
86
|
|
|
$pdo = '';
|
87
|
|
|
if (!empty($pdo)) {
|
88
|
|
|
$profiles = $pdo->getProfiler()->getProfiles();
|
|
|
|
|
89
|
|
|
$profiles = array_filter($profiles, function ($profile) {
|
90
|
|
|
return $profile['function'] == 'perform';
|
91
|
|
|
});
|
92
|
|
|
$profiles = array_map(function ($profile) {
|
93
|
|
|
return array(
|
94
|
|
|
'sql' => $profile['statement'],
|
95
|
|
|
'parameters' => $profile['bind_values'],
|
96
|
|
|
'time' => $profile['duration']
|
97
|
|
|
);
|
98
|
|
|
}, $profiles);
|
99
|
|
|
self::instance()->profiler->setProfiledQueries($profiles);
|
100
|
|
|
}
|
101
|
|
|
self::instance()->profiler->setDisplay(new Particletree\Pqp\Display());
|
102
|
|
|
self::instance()->profiler->display($pdo);
|
103
|
|
|
}
|
104
|
|
|
}
|
105
|
|
|
|
106
|
|
|
}
|
107
|
|
|
|
Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.
As a precaution to avoid these problems better use the long opening tag
<?php
.