Mercurial > hg > isophonics-drupal-site
comparison vendor/doctrine/common/lib/Doctrine/Common/Util/Debug.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
63 | 63 |
64 if (extension_loaded('xdebug')) { | 64 if (extension_loaded('xdebug')) { |
65 ini_set('xdebug.var_display_max_depth', $maxDepth); | 65 ini_set('xdebug.var_display_max_depth', $maxDepth); |
66 } | 66 } |
67 | 67 |
68 $var = self::export($var, $maxDepth++); | 68 $var = self::export($var, $maxDepth); |
69 | 69 |
70 ob_start(); | 70 ob_start(); |
71 var_dump($var); | 71 var_dump($var); |
72 | 72 |
73 $dump = ob_get_contents(); | 73 $dump = ob_get_contents(); |
75 ob_end_clean(); | 75 ob_end_clean(); |
76 | 76 |
77 $dumpText = ($stripTags ? strip_tags(html_entity_decode($dump)) : $dump); | 77 $dumpText = ($stripTags ? strip_tags(html_entity_decode($dump)) : $dump); |
78 | 78 |
79 ini_set('html_errors', $html); | 79 ini_set('html_errors', $html); |
80 | 80 |
81 if ($echo) { | 81 if ($echo) { |
82 echo $dumpText; | 82 echo $dumpText; |
83 } | 83 } |
84 | 84 |
85 return $dumpText; | 85 return $dumpText; |
86 } | 86 } |
87 | 87 |
88 /** | 88 /** |
89 * @param mixed $var | 89 * @param mixed $var |
98 | 98 |
99 if ($var instanceof Collection) { | 99 if ($var instanceof Collection) { |
100 $var = $var->toArray(); | 100 $var = $var->toArray(); |
101 } | 101 } |
102 | 102 |
103 if ($maxDepth) { | 103 if (! $maxDepth) { |
104 if (is_array($var)) { | 104 return is_object($var) ? get_class($var) |
105 $return = []; | |
106 | |
107 foreach ($var as $k => $v) { | |
108 $return[$k] = self::export($v, $maxDepth - 1); | |
109 } | |
110 } else if ($isObj) { | |
111 $return = new \stdclass(); | |
112 if ($var instanceof \DateTime) { | |
113 $return->__CLASS__ = "DateTime"; | |
114 $return->date = $var->format('c'); | |
115 $return->timezone = $var->getTimeZone()->getName(); | |
116 } else { | |
117 $reflClass = ClassUtils::newReflectionObject($var); | |
118 $return->__CLASS__ = ClassUtils::getClass($var); | |
119 | |
120 if ($var instanceof Proxy) { | |
121 $return->__IS_PROXY__ = true; | |
122 $return->__PROXY_INITIALIZED__ = $var->__isInitialized(); | |
123 } | |
124 | |
125 if ($var instanceof \ArrayObject || $var instanceof \ArrayIterator) { | |
126 $return->__STORAGE__ = self::export($var->getArrayCopy(), $maxDepth - 1); | |
127 } | |
128 | |
129 foreach ($reflClass->getProperties() as $reflProperty) { | |
130 $name = $reflProperty->getName(); | |
131 | |
132 $reflProperty->setAccessible(true); | |
133 $return->$name = self::export($reflProperty->getValue($var), $maxDepth - 1); | |
134 } | |
135 } | |
136 } else { | |
137 $return = $var; | |
138 } | |
139 } else { | |
140 $return = is_object($var) ? get_class($var) | |
141 : (is_array($var) ? 'Array(' . count($var) . ')' : $var); | 105 : (is_array($var) ? 'Array(' . count($var) . ')' : $var); |
142 } | 106 } |
107 | |
108 if (is_array($var)) { | |
109 $return = []; | |
110 | |
111 foreach ($var as $k => $v) { | |
112 $return[$k] = self::export($v, $maxDepth - 1); | |
113 } | |
114 | |
115 return $return; | |
116 } | |
117 | |
118 if (! $isObj) { | |
119 return $var; | |
120 } | |
121 | |
122 $return = new \stdclass(); | |
123 if ($var instanceof \DateTimeInterface) { | |
124 $return->__CLASS__ = get_class($var); | |
125 $return->date = $var->format('c'); | |
126 $return->timezone = $var->getTimezone()->getName(); | |
127 | |
128 return $return; | |
129 } | |
130 | |
131 $return->__CLASS__ = ClassUtils::getClass($var); | |
132 | |
133 if ($var instanceof Proxy) { | |
134 $return->__IS_PROXY__ = true; | |
135 $return->__PROXY_INITIALIZED__ = $var->__isInitialized(); | |
136 } | |
137 | |
138 if ($var instanceof \ArrayObject || $var instanceof \ArrayIterator) { | |
139 $return->__STORAGE__ = self::export($var->getArrayCopy(), $maxDepth - 1); | |
140 } | |
141 | |
142 return self::fillReturnWithClassAttributes($var, $return, $maxDepth); | |
143 } | |
144 | |
145 /** | |
146 * Fill the $return variable with class attributes | |
147 * | |
148 * @param object $var | |
149 * @param stdClass $return | |
150 * @param int $maxDepth | |
151 * | |
152 * @return mixed | |
153 */ | |
154 private static function fillReturnWithClassAttributes($var, \stdClass $return, $maxDepth) | |
155 { | |
156 $reflClass = ClassUtils::newReflectionObject($var); | |
157 $parsedAttributes = array(); | |
158 do { | |
159 $currentClassName = $reflClass->getName(); | |
160 | |
161 foreach ($reflClass->getProperties() as $reflProperty) { | |
162 $attributeKey = $reflProperty->isPrivate() ? $currentClassName . '#' : ''; | |
163 $attributeKey .= $reflProperty->getName(); | |
164 | |
165 if (isset($parsedAttributes[$attributeKey])) { | |
166 continue; | |
167 } | |
168 | |
169 $parsedAttributes[$attributeKey] = true; | |
170 | |
171 $name = | |
172 $reflProperty->getName() | |
173 . ($return->__CLASS__ !== $currentClassName || $reflProperty->isPrivate() ? ':' . $currentClassName : '') | |
174 . ($reflProperty->isPrivate() ? ':private' : '') | |
175 . ($reflProperty->isProtected() ? ':protected' : '') | |
176 ; | |
177 | |
178 $reflProperty->setAccessible(true); | |
179 $return->$name = self::export($reflProperty->getValue($var), $maxDepth - 1); | |
180 } | |
181 } while ($reflClass = $reflClass->getParentClass()); | |
143 | 182 |
144 return $return; | 183 return $return; |
145 } | 184 } |
146 | 185 |
147 /** | 186 /** |