/
Init.php
150 lines (127 loc) · 4.57 KB
/
Init.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
// This function is called at the bottom of this file
function FirePHP__main() {
$activate = true;
$force = false;
if(defined('FIREPHP_ACTIVATED')) {
if(constant('FIREPHP_ACTIVATED')===false) {
$activate = false;
} else
if(constant('FIREPHP_ACTIVATED')===true) {
$activate = true;
$force = true;
}
}
if($activate && $force===false) {
// Only activate FirePHP if certain header prefixes are found:
// * x-wf-
// * x-insight
$headers = false;
if(function_exists('getallheaders')) {
$headers = getallheaders();
} else {
$headers = $_SERVER;
}
$activate = false;
foreach( $headers as $name => $value ) {
$name = strtolower($name);
if(substr($name, 0, 5) == 'http_') {
$name = str_replace(' ', '-', str_replace('_', ' ', substr($name, 5)));
}
if(substr($name, 0, 5)=='x-wf-') {
$activate = true;
} else
if(substr($name, 0, 9)=='x-insight') {
$activate = true;
}
}
}
if($activate) {
if(!defined('FIREPHP_ACTIVATED')) {
define('FIREPHP_ACTIVATED', true);
}
// TODO: This may be removed in future?
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(__FILE__)));
spl_autoload_register('FirePHP__autoload');
if (class_exists('FirePHP', false)) {
throw new Exception("The FirePHP class must not be loaded manually!");
}
// NOTE: We need to load this class here so we can get access to the FirePHP class
FirePHP__autoload('FirePHP_Insight');
// ensure the FirePHP class included has the correct version
$version = '0.3'; // @pinf replace '0.3' with '%%VERSION%%'
if(FirePHP::VERSION!=$version) {
throw new Exception("The included FirePHP class has the wrong version! This is likely due to an old version of FirePHP still being on the include path. The old version must be removed or the FirePHP 1.0 classes must have precedence on the include path!");
}
FirePHP::setInstance(new FirePHP_Insight());
if($force===true) {
$GLOBALS['INSIGHT_FORCE_ENABLE'] = true;
}
Insight_Helper__main();
FirePHP::getInstance(true)->setLogToInsightConsole(FirePHP::to('page')->console());
} else {
if(!defined('FIREPHP_ACTIVATED')) {
define('FIREPHP_ACTIVATED', false);
}
class FirePHP {
const VERSION = '0.3'; // @pinf replace '0.3' with '%%VERSION%%'
const LOG = 'LOG';
const INFO = 'INFO';
const WARN = 'WARN';
const ERROR = 'ERROR';
const DUMP = 'DUMP';
const TRACE = 'TRACE';
const EXCEPTION = 'EXCEPTION';
const TABLE = 'TABLE';
const GROUP_START = 'GROUP_START';
const GROUP_END = 'GROUP_END';
protected static $instance = null;
public static function getInstance() {
if(!self::$instance) {
self::$instance = new FirePHP();
}
return self::$instance;
}
public function getEnabled() {
return false;
}
public function detectClientExtension() {
return false;
}
public static function to() {
return self::getInstance();
}
public static function plugin() {
return self::getInstance();
}
public function __call($name, $arguments) {
return self::getInstance();
}
public static function __callStatic($name, $arguments) {
return self::getInstance();
}
}
}
}
function FirePHP__autoload($class)
{
if (strpos($class, 'FirePHP') !== 0 &&
strpos($class, 'Insight') !== 0
) {
return;
}
// find relative
if (file_exists($file = dirname(dirname(__FILE__)) . '/' . str_replace('_', '/', $class) . '.php')) {
require_once($file);
} else
// find in include path
{
foreach (explode(PATH_SEPARATOR, get_include_path()) as $basePath) {
if (file_exists($file = $basePath . '/' . str_replace('_', '/', $class) . '.php')) {
require_once($file);
return;
}
}
}
}
FirePHP__main();