1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/****************************************************************** |
3
|
|
|
mod_debug.php Muze Ariadne |
4
|
|
|
------------------------------------------------------------------ |
5
|
|
|
Author: Wouter Commandeur (Muze) ([email protected]) |
6
|
|
|
Date: 18 march 2003 |
7
|
|
|
|
8
|
|
|
Copyright 2003 Muze |
9
|
|
|
|
10
|
|
|
This file is part of Ariadne. |
11
|
|
|
|
12
|
|
|
Ariadne is free software; you can redistribute it and/or modify |
13
|
|
|
it under the terms of the GNU General Public License as published |
14
|
|
|
by the Free Software Foundation; either version 2 of the License, |
15
|
|
|
or (at your option) any later version. |
16
|
|
|
|
17
|
|
|
Ariadne is distributed in the hope that it will be useful, |
18
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
GNU General Public License for more details. |
21
|
|
|
|
22
|
|
|
You should have received a copy of the GNU General Public License |
23
|
|
|
along with Ariadne; if not, write to the Free Software |
24
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
25
|
|
|
02111-1307 USA |
26
|
|
|
|
27
|
|
|
------------------------------------------------------------------- |
28
|
|
|
|
29
|
|
|
Description: |
30
|
|
|
|
31
|
|
|
Debug Module |
32
|
|
|
|
33
|
|
|
******************************************************************/ |
34
|
|
|
|
35
|
|
|
global $DB; |
36
|
|
|
$DB["all"]=5; |
37
|
|
|
$DB["store"]=4; |
38
|
|
|
$DB["class"]=3; |
39
|
|
|
$DB["object"]=2; |
40
|
|
|
$DB["pinp"]=1; |
41
|
|
|
$DB["off"]=0; |
42
|
|
|
$DB["level"]=$DB["off"]; |
43
|
|
|
$DB["stream"]="all"; |
44
|
|
|
$DB["file"]=false; |
45
|
|
|
$DB["method"]["loader"] = true; |
46
|
|
|
$DB["method"]["firebug"] = false; |
47
|
|
|
$DB["method"]["syslog"] = false; |
48
|
|
|
$DB["method"]["file"] = false; |
49
|
|
|
$DB["wasUsed"] = 0; |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
function debugon($level="pinp", $stream="all") { |
53
|
|
|
global $DB; |
54
|
|
|
$debugison = ""; |
55
|
|
|
if( $DB["method"]["file"] && $DB["file"] ) { |
56
|
|
|
$DB["fp"]=@fopen($DB["file"], "a+"); |
57
|
|
|
if ($DB["fp"]) { |
58
|
|
|
$debugison .= " [file ".$DB["file"]."]"; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
/* Check if we're debugging to the loader debug_print function and |
62
|
|
|
the loader is capable of debugging. |
63
|
|
|
*/ |
64
|
|
|
if( $DB["method"]["loader"] && function_exists("debug_print")) { |
65
|
|
|
$debugison .= " [loader]"; |
66
|
|
|
} |
67
|
|
|
if( $DB["method"]["syslog"] ) { |
68
|
|
|
$debugison .= " [syslog]"; |
69
|
|
|
} |
70
|
|
|
if( $DB["method"]["firebug"] ) { |
71
|
|
|
$debugison .= " [firebug]"; |
72
|
|
|
} |
73
|
|
|
if( $debugison != "" ) { |
74
|
|
|
$DB["level"] = $DB[$level]; |
75
|
|
|
$DB["stream"] = $stream; |
76
|
|
|
debug("Debugging ON ".$debugison,$level,$stream); |
77
|
|
|
} |
78
|
|
|
$DB["wasUsed"]++; |
79
|
|
|
return true; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
function debugoff() { |
83
|
|
|
global $DB; |
84
|
|
|
$debugisoff = ""; |
85
|
|
|
if( $DB["method"]["file"] && $DB["file"] && $DB["fp"] ) { |
86
|
|
|
@fclose($DB["fp"]); |
|
|
|
|
87
|
|
|
$debugisoff .= " [file ".$DB["file"]."]"; |
88
|
|
|
} |
89
|
|
|
/* Check if we're debugging to the loader debug_print function and |
90
|
|
|
the loader is capable of debugging. |
91
|
|
|
*/ |
92
|
|
|
if( $DB["method"]["loader"] && function_exists("debug_print") ) { |
93
|
|
|
$debugisoff .= " [loader]"; |
94
|
|
|
} |
95
|
|
|
if( $DB["method"]["syslog"] ) { |
96
|
|
|
$debugisoff .= " [syslog]"; |
97
|
|
|
} |
98
|
|
|
if( $debugisoff != "" && $DB["level"] > 0) { |
99
|
|
|
debug("Debugging OFF ".$debugisoff,$DB["level"],$DB["stream"]); |
100
|
|
|
if( $DB["fp"] ) { |
101
|
|
|
@fclose($DB["fp"]); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
$DB["level"]=$DB["off"]; |
104
|
|
|
} |
105
|
|
|
return true; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
function debuglevel($level) { |
109
|
|
|
global $DB; |
110
|
|
|
return ($DB["level"] >= $DB[$level]); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
function debug($text, $level="pinp", $stream="all", $indent="") { |
114
|
198 |
|
global $DB, $DB_INDENT; |
115
|
198 |
|
if ( ! isset($DB[$level]) ) { |
116
|
|
|
$level = "pinp"; |
117
|
|
|
} |
118
|
198 |
|
if( $DB["level"] >= $DB[$level] && (($DB["stream"]=="all")||($DB["stream"]==$stream) ) ) { |
119
|
|
|
/* format the message */ |
120
|
|
|
|
121
|
|
|
$message = "[".$level."][".$stream."] ".$text; |
122
|
|
|
$timestamping = date("H:i:s"); |
123
|
|
|
/* handle indentation */ |
124
|
|
|
if( $indent=="OUT" ) { |
125
|
|
|
$DB_INDENT = substr($DB_INDENT,0,-2); |
126
|
|
|
} |
127
|
|
|
if( $indent=="IN" ) { |
128
|
|
|
$DB_INDENT.=" "; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
if( $DB["method"]["file"] && $DB["fp"] ) { |
132
|
|
|
@fwrite($DB["fp"], "(".$timestamping.")".$DB_INDENT.$message."\n"); |
|
|
|
|
133
|
|
|
@fflush($DB["fp"]); |
|
|
|
|
134
|
|
|
} |
135
|
|
|
/* Check if we're debugging to the loader debug_print function and |
136
|
|
|
the loader is capable of debugging. |
137
|
|
|
*/ |
138
|
|
|
if( $DB["method"]["loader"] && function_exists("debug_print") ) { |
139
|
|
|
debug_print( "(".$timestamping.")".$DB_INDENT.$message."\n" ); |
140
|
|
|
} |
141
|
|
|
if( $DB["method"]["syslog"] ) { |
142
|
|
|
syslog(LOG_NOTICE,"(Ariadne) ".$DB_INDENT.$message); |
143
|
|
|
} |
144
|
|
|
if ( $DB["method"]["firebug"] ) { |
145
|
|
|
ar('beta/firebug')->log($text,"[".$level."][".$stream."]"); |
146
|
|
|
} |
147
|
|
|
} |
148
|
198 |
|
} |
149
|
|
|
|
150
|
|
|
function debug_serialize( $var, $level="pinp", $stream="all" ) { |
151
|
184 |
|
global $DB; |
152
|
184 |
|
if( $DB["level"] >= $DB[$level] && (($DB["stream"]=="all")||($DB["stream"]==$stream) ) ) { |
153
|
|
|
return serialize($var); |
154
|
|
|
} |
155
|
184 |
|
return ""; |
156
|
|
|
} |
157
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.