-
Notifications
You must be signed in to change notification settings - Fork 7
/
phpfuncs.php
132 lines (115 loc) · 4.42 KB
/
phpfuncs.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
<?php
/*
* This file is here for convenience; the actual functions used by the debugger
* are in VimDebugger.py at the bottom
*/
function __xdbg_get_value($var, $maxDepth=2) {
$return = null;
$isObj = is_object($var);
if ($isObj && in_array("Doctrine\Common\Collections\Collection", class_implements($var))) {
$var = $var->toArray();
}
if ($maxDepth > 0) {
if (is_array($var)) {
$return = array();
foreach ($var as $k => $v) {
$return[$k] = __xdbg_get_value($v, $maxDepth - 1);
}
} else if ($isObj) {
if ($var instanceof \DateTime) {
$return = $var->format("c");
} else {
$reflClass = new \ReflectionClass(get_class($var));
$return = new \stdclass();
$return->{"__CLASS__"} = get_class($var);
if (is_a($var, "Doctrine\\ORM\\Proxy\\Proxy") && ! $var->__isInitialized__) {
$reflProperty = $reflClass->getProperty("_identifier");
$reflProperty->setAccessible(true);
foreach ($reflProperty->getValue($var) as $name => $value) {
$return->$name = __xdbg_get_value($value, $maxDepth - 1);
}
} else {
$excludeProperties = array();
if (is_a($var, "Doctrine\\ORM\\Proxy\\Proxy")) {
$excludeProperties = array("_entityPersister", "__isInitialized__", "_identifier");
foreach ($reflClass->getProperties() as $reflProperty) {
$name = $reflProperty->getName();
if ( ! in_array($name, $excludeProperties)) {
$reflProperty->setAccessible(true);
$return->$name = __xdbg_get_value($reflProperty->getValue($var), $maxDepth - 1);
}
}
} else {
$return = $var;
}
}
$return = __xdbg_get_object($return, $maxDepth-1);
}
} else {
$return = $var;
}
} else {
$return = is_object($var) ? get_class($var)
: (is_array($var) ? "Array(" . count($var) . ")" : $var);
}
return $return;
}
function __xdbg_get_propertyList($propList, $item, $maxDepth=2) {
$output = array();
foreach ($propList as $prop) {
$static = $prop->isStatic() ? "static " : "";
$vis = $prop->isProtected() ? "protected" : $prop->isPrivate() ? "private" : "public";
$name = $prop->getName();
$val = null;
if (!$prop->isPublic()) {
$prop->setAccessible(true);
$val = $prop->getValue($item);
$prop->setAccessible(false);
} else {
$val = $prop->getValue($item);
}
$desc = $static."$vis \$$name";
$output[$desc] = __xdbg_get_value($val, $maxDepth);
}
return $output;
}
function __xdbg_get_methodList($methodList) {
$output = array();
foreach ($methodList as $method) {
$static = $method->isStatic() ? "static " : "";
$vis = $method->isPrivate() ? "private" : $method->isProtected() ? "protected" : "public";
$name = $method->getName();
$params = array();
$plist = $method->getParameters();
foreach ($plist as $param) {
$params[] = "$" . $param->getName();
}
$desc = $static."$vis $name(" . implode(", ", $params) . ")";
$output[] = $desc;
}
return $output;
}
function __xdbg_get_object($var, $maxDepth=2) {
$entry = array();
$class = get_class($var);
$ref = new ReflectionClass($var);
$entry = array(
"properties" => __xdbg_get_propertyList($ref->getProperties(), $var, $maxDepth-1),
"methods" => __xdbg_get_methodList($ref->getMethods()),
"className" => $class,
"isClass" => true,
);
return $entry;
}
function __xdbg_get_objList(array $listx2) {
$outputFull = array();
foreach ($listx2 as $list) {
$output = array();
foreach ($list as $item) {
$output[] = __xdbg_get_value($item);
}
$outputFull[] = $output;
}
return @json_encode($outputFull);
}
function __xdbg_run($method) { ob_start(); $method(); $tmp = ob_get_contents(); ob_end_clean(); return $tmp; }