Permalink
Newer
Older
100644 133 lines (115 sloc) 4.42 KB
1
<?php
2
3
/*
4
* This file is here for convenience; the actual functions used by the debugger
5
* are in VimDebugger.py at the bottom
6
*/
7
8
function __xdbg_get_value($var, $maxDepth=2) {
9
$return = null;
10
$isObj = is_object($var);
11
12
if ($isObj && in_array("Doctrine\Common\Collections\Collection", class_implements($var))) {
13
$var = $var->toArray();
14
}
15
16
if ($maxDepth > 0) {
17
if (is_array($var)) {
18
$return = array();
19
20
foreach ($var as $k => $v) {
21
$return[$k] = __xdbg_get_value($v, $maxDepth - 1);
22
}
23
} else if ($isObj) {
24
if ($var instanceof \DateTime) {
25
$return = $var->format("c");
26
} else {
27
$reflClass = new \ReflectionClass(get_class($var));
28
$return = new \stdclass();
29
$return->{"__CLASS__"} = get_class($var);
30
31
if (is_a($var, "Doctrine\\ORM\\Proxy\\Proxy") && ! $var->__isInitialized__) {
32
$reflProperty = $reflClass->getProperty("_identifier");
33
$reflProperty->setAccessible(true);
34
35
foreach ($reflProperty->getValue($var) as $name => $value) {
36
$return->$name = __xdbg_get_value($value, $maxDepth - 1);
37
}
38
} else {
39
$excludeProperties = array();
40
41
if (is_a($var, "Doctrine\\ORM\\Proxy\\Proxy")) {
42
$excludeProperties = array("_entityPersister", "__isInitialized__", "_identifier");
43
44
foreach ($reflClass->getProperties() as $reflProperty) {
45
$name = $reflProperty->getName();
46
47
if ( ! in_array($name, $excludeProperties)) {
48
$reflProperty->setAccessible(true);
49
50
$return->$name = __xdbg_get_value($reflProperty->getValue($var), $maxDepth - 1);
51
}
52
}
53
} else {
54
$return = $var;
55
}
56
}
57
$return = __xdbg_get_object($return, $maxDepth-1);
58
}
59
} else {
60
$return = $var;
61
}
62
} else {
63
$return = is_object($var) ? get_class($var)
64
: (is_array($var) ? "Array(" . count($var) . ")" : $var);
65
}
66
67
return $return;
68
}
69
70
function __xdbg_get_propertyList($propList, $item, $maxDepth=2) {
71
$output = array();
72
foreach ($propList as $prop) {
73
$static = $prop->isStatic() ? "static " : "";
74
$vis = $prop->isProtected() ? "protected" : $prop->isPrivate() ? "private" : "public";
75
$name = $prop->getName();
76
$val = null;
77
if (!$prop->isPublic()) {
78
$prop->setAccessible(true);
79
$val = $prop->getValue($item);
80
$prop->setAccessible(false);
81
} else {
82
$val = $prop->getValue($item);
83
}
84
$desc = $static."$vis \$$name";
85
$output[$desc] = __xdbg_get_value($val, $maxDepth);
86
}
87
return $output;
88
}
89
90
function __xdbg_get_methodList($methodList) {
91
$output = array();
92
foreach ($methodList as $method) {
93
$static = $method->isStatic() ? "static " : "";
94
$vis = $method->isPrivate() ? "private" : $method->isProtected() ? "protected" : "public";
95
$name = $method->getName();
96
$params = array();
97
$plist = $method->getParameters();
98
foreach ($plist as $param) {
99
$params[] = "$" . $param->getName();
100
}
101
$desc = $static."$vis $name(" . implode(", ", $params) . ")";
102
$output[] = $desc;
103
}
104
return $output;
105
}
106
107
function __xdbg_get_object($var, $maxDepth=2) {
108
$entry = array();
109
$class = get_class($var);
110
$ref = new ReflectionClass($var);
111
$entry = array(
112
"properties" => __xdbg_get_propertyList($ref->getProperties(), $var, $maxDepth-1),
113
"methods" => __xdbg_get_methodList($ref->getMethods()),
114
"className" => $class,
115
"isClass" => true,
116
);
117
return $entry;
118
}
119
120
function __xdbg_get_objList(array $listx2) {
121
$outputFull = array();
122
foreach ($listx2 as $list) {
123
$output = array();
124
foreach ($list as $item) {
125
$output[] = __xdbg_get_value($item);
126
}
127
$outputFull[] = $output;
128
}
129
return @json_encode($outputFull);
130
}
131
132
function __xdbg_run($method) { ob_start(); $method(); $tmp = ob_get_contents(); ob_end_clean(); return $tmp; }