-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUecode.php
More file actions
executable file
·260 lines (236 loc) · 7.37 KB
/
Uecode.php
File metadata and controls
executable file
·260 lines (236 loc) · 7.37 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
/**
* Uecode Library Base Class
*
* @author Aaron Scherer
* @date 2013
* @copyright
*/
class Uecode
{
/**
* This function is used to dump, in a readable format, a given object or array.
*
*
* @static
*
* @param mixed $var Array or Object to Dump
* @param int $depth depth to decent into $var
* @param boolean $die Do we die after being called
* @param boolean $dumpOut Do we return our output instead of echoing it
*
* @return string
*/
public static function dump( $var, $depth = 5, $die = false, $dumpOut = false )
{
$echo = '';
$scope = false;
$prefix = 'unique';
$suffix = 'value';
$isCli = php_sapi_name() === 'cli';
if ( $scope ) {
$vals = $scope;
} else {
$vals = $GLOBALS;
}
$old = $var;
$var = $new = $prefix . rand() . $suffix;
$vname = false;
foreach ( $vals as $key => $val ) {
if ( $val === $new ) {
$vname = $key;
}
}
$var = $old;
$echo .= "<div class='debugDump'>\n\t\t\t";
$echo .= "\n\t\t\t\t<pre style='word-wrap: break-word'>";
$echo .= "\n\t\t\t\t\t" . self::do_dump( $var, '$' . $vname, null, null, $depth );
$echo .= "\n\t\t\t\t</pre>\n\t\t\t</div>";
if( $isCli ) {
$echo = strip_tags( str_replace( " ", " ", $echo ) );
}
if ( $dumpOut === false ) {
if ( $die ) {
if( $isCli ) {
die( $echo );
}
die( "<!DOCTYPE html>\n<html>\n\t<head>\n\t\t<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n\t\t<title>Dump</title>\n\t</head>\n\t<body>\n\t\t" . $echo . "\n\t</body>\n</html>" );
}
echo $echo;
return null;
}
return $echo;
}
/**
* This function is called by Uecode::dump() that does all the logic.
*
* @static
*
* @param mixed $var
* @param null $var_name
* @param null $indent
* @param null $reference
* @param int $depth
*
* @return string
*/
private static function do_dump( &$var, $var_name = null, $indent = null, $reference = null, $depth = 5 )
{
$echo = "\n";
$BADCLASSES = array( 'DateTimeZone', 'DateTime' );
$BADMETHODS = array(
'get',
'getEscaper',
'getFlash',
'getUriForPath',
'getMimeType',
'getFormat',
'getParameter',
'getLocateExpression',
'getListTableConstraintsSQL',
'getListTableIndexesSQL'
);
if ( $depth < 0 ) {
return;
}
$do_dump_indent = "\t<span style='color:#eeeeee;'>|</span> ";
$reference = $reference . $var_name;
$keyvar = 'the_do_dump_recursion_protection_scheme';
$keyname = 'referenced_object_name';
if ( is_array( $var ) && isset( $var[ $keyvar ] ) ) {
$real_var = & $var[ $keyvar ];
$real_name = & $var[ $keyname ];
$type = ucfirst( gettype( $real_var ) );
$echo .= "$indent$var_name <span style='color:#a2a2a2'>$type</span> = <span style='color:#e87800;'>&$real_name</span><br>";
} else {
$var = array( $keyvar => $var, $keyname => $reference );
$avar = & $var[ $keyvar ];
$type = ucfirst( gettype( $avar ) );
if ( $type == "String" ) {
$type_color = "<span style='color:green'>";
} elseif ( $type == "Integer" ) {
$type_color = "<span style='color:red'>";
} elseif ( $type == "Double" ) {
$type_color = "<span style='color:#0099c5'>";
$type = "Float";
} elseif ( $type == "Boolean" ) {
$type_color = "<span style='color:#92008d'>";
} elseif ( $type == "NULL" ) {
$type_color = "<span style='color:black'>";
}
if ( is_array( $avar ) ) {
$count = count( $avar );
$echo .= "$indent" . ( $var_name ? "$var_name => " : "" ) . "<span style='color:#a2a2a2'>$type ($count)</span><br>$indent(<br>";
$keys = array_keys( $avar );
foreach ( $keys as $name ) {
$value = & $avar[ $name ];
$echo .= self::do_dump( $value, "['$name']", $indent . $do_dump_indent, $reference, $depth - 1 );
}
$echo .= "$indent)<br>";
} elseif ( is_object( $avar ) ) {
$class = get_class( $avar );
$echo .= "$indent$var_name <span style='color:#a2a2a2'>$class Object</span><br>$indent(<br>";
$props = get_class_methods( $avar );
foreach ( $props as $prop ) {
if (
( strpos( $prop, 'get' ) === 0 ) &&
( strpos( $prop, 'set' ) !== 0 ) &&
( $prop != 'get' ) &&
( strpos( $prop, '__' ) !== 0 )
) {
$r = new ReflectionMethod( $class, $prop );
$params = $r->getParameters();
if ( !in_array( $class, $BADCLASSES ) && !in_array( $prop, $BADMETHODS ) && empty( $params ) ) {
try {
$item = $avar->$prop();
if ( strpos( $prop, 'get' ) === 0 ) {
$name = substr( $prop, 3 );
}
$echo .= self::do_dump(
$item,
"$name",
$indent . $do_dump_indent,
$reference,
$depth - 1
);
} catch( Exception $e ) {
$echo .= "NoData";
}
}
}
}
$vars = get_object_vars( $avar );
foreach ( $vars as $k => $v ) {
if ( $k != '__isInitialized__' ) {
$echo .= self::do_dump( $v, "$k", $indent . $do_dump_indent, $reference, $depth - 1 );
}
}
$echo .= "$indent)<br>";
} elseif ( is_int( $avar ) ) {
$echo .= "$indent$var_name = <span style='color:#a2a2a2'>$type(" . strlen(
$avar
) . ")</span> $type_color$avar</span><br>";
} elseif ( is_string( $avar ) ) {
$echo .= "$indent$var_name = <span style='color:#a2a2a2'>$type(" . strlen(
$avar
) . ")</span> $type_color\"" . htmlentities( $avar ) . "\"</span><br>";
} elseif ( is_float( $avar ) ) {
$echo .= "$indent$var_name = <span style='color:#a2a2a2'>$type(" . strlen(
$avar
) . ")</span> $type_color$avar</span><br>";
} elseif ( is_bool( $avar ) ) {
$echo .= "$indent$var_name = <span style='color:#a2a2a2'>$type(" . strlen(
$avar
) . ")</span> $type_color" . ( $avar == 1 ? "TRUE" : "FALSE" ) . "</span><br>";
} elseif ( is_null( $avar ) ) {
$echo .= "$indent$var_name = <span style='color:#a2a2a2'>$type(" . strlen(
$avar
) . ")</span> {$type_color}NULL</span><br>";
} else {
$echo .= "$indent$var_name = <span style='color:#a2a2a2'>$type(" . strlen(
$avar
) . ")</span> $avar<br>";
}
$var = $var[ $keyvar ];
}
return $echo;
}
/**
* Parse a URL
*
* @param string $url Url to parse
*/
public static function parseUrl( $url )
{
$r = "^(?:(?P<scheme>\w+)://)?";
$r .= "(?:(?P<login>\w+):(?P<pass>\w+)@)?";
$r .= "(?P<host>(?:(?P<subdomain>[-\w\.]+)\.)?" . "(?P<domain>[-\w]+\.(?P<extension>\w+)))";
$r .= "(?::(?P<port>\d+))?";
$r .= "(?P<path>[\w/-]*/(?P<file>[\w-]+(?:\.\w+)?)?)?";
$r .= "(?:\?(?P<arg>[\w=&]+))?";
$r .= "(?:#(?P<anchor>\w+))?";
$r = "!$r!";
preg_match( $r, $url, $out );
$joinedExtensions = array( 'us.com', 'us.org', 'us.net' );
if ( in_array( $out[ 'domain' ], $joinedExtensions ) ) {
if ( strpos( $out[ 'subdomain' ], '.' ) !== false ) {
$temp = explode( '.', $out[ 'subdomain' ] );
$out[ 'subdomain' ] = $temp[ 0 ];
$out[ 'extension' ] = $out[ 'domain' ];
$out[ 'domain' ] = $temp[ 1 ] . '.' . $out[ 'domain' ];
} else {
$out[ 'extension' ] = $out[ 'domain' ];
$out[ 'domain' ] = $out[ 'subdomain' ] . '.' . $out[ 'domain' ];
$out[ 'subdomain' ] = '';
}
}
foreach ( $out as $key => $value ) {
if ( is_numeric( $key ) ) {
unset( $out[ $key ] );
}
}
$out[ 'pathFull' ] = $out[ 'path' ];
$out[ 'path' ] = explode( '/', trim( $out[ 'path' ], '/' ) );
return $out;
}
}