Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/var-dumper/Caster/ReflectionCaster.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
18 * | 18 * |
19 * @author Nicolas Grekas <p@tchwork.com> | 19 * @author Nicolas Grekas <p@tchwork.com> |
20 */ | 20 */ |
21 class ReflectionCaster | 21 class ReflectionCaster |
22 { | 22 { |
23 private static $extraMap = array( | 23 private static $extraMap = [ |
24 'docComment' => 'getDocComment', | 24 'docComment' => 'getDocComment', |
25 'extension' => 'getExtensionName', | 25 'extension' => 'getExtensionName', |
26 'isDisabled' => 'isDisabled', | 26 'isDisabled' => 'isDisabled', |
27 'isDeprecated' => 'isDeprecated', | 27 'isDeprecated' => 'isDeprecated', |
28 'isInternal' => 'isInternal', | 28 'isInternal' => 'isInternal', |
29 'isUserDefined' => 'isUserDefined', | 29 'isUserDefined' => 'isUserDefined', |
30 'isGenerator' => 'isGenerator', | 30 'isGenerator' => 'isGenerator', |
31 'isVariadic' => 'isVariadic', | 31 'isVariadic' => 'isVariadic', |
32 ); | 32 ]; |
33 | 33 |
34 public static function castClosure(\Closure $c, array $a, Stub $stub, $isNested, $filter = 0) | 34 public static function castClosure(\Closure $c, array $a, Stub $stub, $isNested, $filter = 0) |
35 { | 35 { |
36 $prefix = Caster::PREFIX_VIRTUAL; | 36 $prefix = Caster::PREFIX_VIRTUAL; |
37 $c = new \ReflectionFunction($c); | 37 $c = new \ReflectionFunction($c); |
38 | 38 |
39 $stub->class = 'Closure'; // HHVM generates unique class names for closures | 39 $stub->class = 'Closure'; // HHVM generates unique class names for closures |
40 $a = static::castFunctionAbstract($c, $a, $stub, $isNested, $filter); | 40 $a = static::castFunctionAbstract($c, $a, $stub, $isNested, $filter); |
41 | |
42 if (false === strpos($c->name, '{closure}')) { | |
43 $stub->class = isset($a[$prefix.'class']) ? $a[$prefix.'class']->value.'::'.$c->name : $c->name; | |
44 unset($a[$prefix.'class']); | |
45 } | |
41 | 46 |
42 if (isset($a[$prefix.'parameters'])) { | 47 if (isset($a[$prefix.'parameters'])) { |
43 foreach ($a[$prefix.'parameters']->value as &$v) { | 48 foreach ($a[$prefix.'parameters']->value as &$v) { |
44 $param = $v; | 49 $param = $v; |
45 $v = new EnumStub(array()); | 50 $v = new EnumStub([]); |
46 foreach (static::castParameter($param, array(), $stub, true) as $k => $param) { | 51 foreach (static::castParameter($param, [], $stub, true) as $k => $param) { |
47 if ("\0" === $k[0]) { | 52 if ("\0" === $k[0]) { |
48 $v->value[substr($k, 3)] = $param; | 53 $v->value[substr($k, 3)] = $param; |
49 } | 54 } |
50 } | 55 } |
51 unset($v->value['position'], $v->value['isVariadic'], $v->value['byReference'], $v); | 56 unset($v->value['position'], $v->value['isVariadic'], $v->value['byReference'], $v); |
83 | 88 |
84 public static function castType(\ReflectionType $c, array $a, Stub $stub, $isNested) | 89 public static function castType(\ReflectionType $c, array $a, Stub $stub, $isNested) |
85 { | 90 { |
86 $prefix = Caster::PREFIX_VIRTUAL; | 91 $prefix = Caster::PREFIX_VIRTUAL; |
87 | 92 |
88 $a += array( | 93 $a += [ |
89 $prefix.'name' => $c instanceof \ReflectionNamedType ? $c->getName() : $c->__toString(), | 94 $prefix.'name' => $c instanceof \ReflectionNamedType ? $c->getName() : $c->__toString(), |
90 $prefix.'allowsNull' => $c->allowsNull(), | 95 $prefix.'allowsNull' => $c->allowsNull(), |
91 $prefix.'isBuiltin' => $c->isBuiltin(), | 96 $prefix.'isBuiltin' => $c->isBuiltin(), |
92 ); | 97 ]; |
93 | 98 |
94 return $a; | 99 return $a; |
95 } | 100 } |
96 | 101 |
97 public static function castReflectionGenerator(\ReflectionGenerator $c, array $a, Stub $stub, $isNested) | 102 public static function castReflectionGenerator(\ReflectionGenerator $c, array $a, Stub $stub, $isNested) |
100 | 105 |
101 if ($c->getThis()) { | 106 if ($c->getThis()) { |
102 $a[$prefix.'this'] = new CutStub($c->getThis()); | 107 $a[$prefix.'this'] = new CutStub($c->getThis()); |
103 } | 108 } |
104 $function = $c->getFunction(); | 109 $function = $c->getFunction(); |
105 $frame = array( | 110 $frame = [ |
106 'class' => isset($function->class) ? $function->class : null, | 111 'class' => isset($function->class) ? $function->class : null, |
107 'type' => isset($function->class) ? ($function->isStatic() ? '::' : '->') : null, | 112 'type' => isset($function->class) ? ($function->isStatic() ? '::' : '->') : null, |
108 'function' => $function->name, | 113 'function' => $function->name, |
109 'file' => $c->getExecutingFile(), | 114 'file' => $c->getExecutingFile(), |
110 'line' => $c->getExecutingLine(), | 115 'line' => $c->getExecutingLine(), |
111 ); | 116 ]; |
112 if ($trace = $c->getTrace(DEBUG_BACKTRACE_IGNORE_ARGS)) { | 117 if ($trace = $c->getTrace(DEBUG_BACKTRACE_IGNORE_ARGS)) { |
113 $function = new \ReflectionGenerator($c->getExecutingGenerator()); | 118 $function = new \ReflectionGenerator($c->getExecutingGenerator()); |
114 array_unshift($trace, array( | 119 array_unshift($trace, [ |
115 'function' => 'yield', | 120 'function' => 'yield', |
116 'file' => $function->getExecutingFile(), | 121 'file' => $function->getExecutingFile(), |
117 'line' => $function->getExecutingLine() - 1, | 122 'line' => $function->getExecutingLine() - 1, |
118 )); | 123 ]); |
119 $trace[] = $frame; | 124 $trace[] = $frame; |
120 $a[$prefix.'trace'] = new TraceStub($trace, false, 0, -1, -1); | 125 $a[$prefix.'trace'] = new TraceStub($trace, false, 0, -1, -1); |
121 } else { | 126 } else { |
122 $function = new FrameStub($frame, false, true); | 127 $function = new FrameStub($frame, false, true); |
123 $function = ExceptionCaster::castFrameStub($function, array(), $function, true); | 128 $function = ExceptionCaster::castFrameStub($function, [], $function, true); |
124 $a[$prefix.'executing'] = new EnumStub(array( | 129 $a[$prefix.'executing'] = new EnumStub([ |
125 "\0~separator= \0".$frame['class'].$frame['type'].$frame['function'].'()' => $function[$prefix.'src'], | 130 "\0~separator= \0".$frame['class'].$frame['type'].$frame['function'].'()' => $function[$prefix.'src'], |
126 )); | 131 ]); |
127 } | 132 } |
128 | 133 |
129 $a[Caster::PREFIX_VIRTUAL.'closed'] = false; | 134 $a[Caster::PREFIX_VIRTUAL.'closed'] = false; |
130 | 135 |
131 return $a; | 136 return $a; |
137 | 142 |
138 if ($n = \Reflection::getModifierNames($c->getModifiers())) { | 143 if ($n = \Reflection::getModifierNames($c->getModifiers())) { |
139 $a[$prefix.'modifiers'] = implode(' ', $n); | 144 $a[$prefix.'modifiers'] = implode(' ', $n); |
140 } | 145 } |
141 | 146 |
142 self::addMap($a, $c, array( | 147 self::addMap($a, $c, [ |
143 'extends' => 'getParentClass', | 148 'extends' => 'getParentClass', |
144 'implements' => 'getInterfaceNames', | 149 'implements' => 'getInterfaceNames', |
145 'constants' => 'getConstants', | 150 'constants' => 'getConstants', |
146 )); | 151 ]); |
147 | 152 |
148 foreach ($c->getProperties() as $n) { | 153 foreach ($c->getProperties() as $n) { |
149 $a[$prefix.'properties'][$n->name] = $n; | 154 $a[$prefix.'properties'][$n->name] = $n; |
150 } | 155 } |
151 | 156 |
162 | 167 |
163 public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, array $a, Stub $stub, $isNested, $filter = 0) | 168 public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, array $a, Stub $stub, $isNested, $filter = 0) |
164 { | 169 { |
165 $prefix = Caster::PREFIX_VIRTUAL; | 170 $prefix = Caster::PREFIX_VIRTUAL; |
166 | 171 |
167 self::addMap($a, $c, array( | 172 self::addMap($a, $c, [ |
168 'returnsReference' => 'returnsReference', | 173 'returnsReference' => 'returnsReference', |
169 'returnType' => 'getReturnType', | 174 'returnType' => 'getReturnType', |
170 'class' => 'getClosureScopeClass', | 175 'class' => 'getClosureScopeClass', |
171 'this' => 'getClosureThis', | 176 'this' => 'getClosureThis', |
172 )); | 177 ]); |
173 | 178 |
174 if (isset($a[$prefix.'returnType'])) { | 179 if (isset($a[$prefix.'returnType'])) { |
175 $v = $a[$prefix.'returnType']; | 180 $v = $a[$prefix.'returnType']; |
176 $v = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString(); | 181 $v = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString(); |
177 $a[$prefix.'returnType'] = new ClassStub($a[$prefix.'returnType']->allowsNull() ? '?'.$v : $v, array(class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '')); | 182 $a[$prefix.'returnType'] = new ClassStub($a[$prefix.'returnType']->allowsNull() ? '?'.$v : $v, [class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '']); |
178 } | 183 } |
179 if (isset($a[$prefix.'class'])) { | 184 if (isset($a[$prefix.'class'])) { |
180 $a[$prefix.'class'] = new ClassStub($a[$prefix.'class']); | 185 $a[$prefix.'class'] = new ClassStub($a[$prefix.'class']); |
181 } | 186 } |
182 if (isset($a[$prefix.'this'])) { | 187 if (isset($a[$prefix.'this'])) { |
197 $a[$prefix.'parameters'] = new EnumStub($a[$prefix.'parameters']); | 202 $a[$prefix.'parameters'] = new EnumStub($a[$prefix.'parameters']); |
198 } | 203 } |
199 | 204 |
200 if ($v = $c->getStaticVariables()) { | 205 if ($v = $c->getStaticVariables()) { |
201 foreach ($v as $k => &$v) { | 206 foreach ($v as $k => &$v) { |
202 if (is_object($v)) { | 207 if (\is_object($v)) { |
203 $a[$prefix.'use']['$'.$k] = new CutStub($v); | 208 $a[$prefix.'use']['$'.$k] = new CutStub($v); |
204 } else { | 209 } else { |
205 $a[$prefix.'use']['$'.$k] = &$v; | 210 $a[$prefix.'use']['$'.$k] = &$v; |
206 } | 211 } |
207 } | 212 } |
231 $prefix = Caster::PREFIX_VIRTUAL; | 236 $prefix = Caster::PREFIX_VIRTUAL; |
232 | 237 |
233 // Added by HHVM | 238 // Added by HHVM |
234 unset($a['info']); | 239 unset($a['info']); |
235 | 240 |
236 self::addMap($a, $c, array( | 241 self::addMap($a, $c, [ |
237 'position' => 'getPosition', | 242 'position' => 'getPosition', |
238 'isVariadic' => 'isVariadic', | 243 'isVariadic' => 'isVariadic', |
239 'byReference' => 'isPassedByReference', | 244 'byReference' => 'isPassedByReference', |
240 'allowsNull' => 'allowsNull', | 245 'allowsNull' => 'allowsNull', |
241 )); | 246 ]); |
242 | 247 |
243 if (method_exists($c, 'getType')) { | 248 if (method_exists($c, 'getType')) { |
244 if ($v = $c->getType()) { | 249 if ($v = $c->getType()) { |
245 $a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString(); | 250 $a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString(); |
246 } | 251 } |
248 $a[$prefix.'typeHint'] = $v[1]; | 253 $a[$prefix.'typeHint'] = $v[1]; |
249 } | 254 } |
250 | 255 |
251 if (isset($a[$prefix.'typeHint'])) { | 256 if (isset($a[$prefix.'typeHint'])) { |
252 $v = $a[$prefix.'typeHint']; | 257 $v = $a[$prefix.'typeHint']; |
253 $a[$prefix.'typeHint'] = new ClassStub($v, array(class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '')); | 258 $a[$prefix.'typeHint'] = new ClassStub($v, [class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '']); |
254 } else { | 259 } else { |
255 unset($a[$prefix.'allowsNull']); | 260 unset($a[$prefix.'allowsNull']); |
256 } | 261 } |
257 | 262 |
258 try { | 263 try { |
281 return $a; | 286 return $a; |
282 } | 287 } |
283 | 288 |
284 public static function castExtension(\ReflectionExtension $c, array $a, Stub $stub, $isNested) | 289 public static function castExtension(\ReflectionExtension $c, array $a, Stub $stub, $isNested) |
285 { | 290 { |
286 self::addMap($a, $c, array( | 291 self::addMap($a, $c, [ |
287 'version' => 'getVersion', | 292 'version' => 'getVersion', |
288 'dependencies' => 'getDependencies', | 293 'dependencies' => 'getDependencies', |
289 'iniEntries' => 'getIniEntries', | 294 'iniEntries' => 'getIniEntries', |
290 'isPersistent' => 'isPersistent', | 295 'isPersistent' => 'isPersistent', |
291 'isTemporary' => 'isTemporary', | 296 'isTemporary' => 'isTemporary', |
292 'constants' => 'getConstants', | 297 'constants' => 'getConstants', |
293 'functions' => 'getFunctions', | 298 'functions' => 'getFunctions', |
294 'classes' => 'getClasses', | 299 'classes' => 'getClasses', |
295 )); | 300 ]); |
296 | 301 |
297 return $a; | 302 return $a; |
298 } | 303 } |
299 | 304 |
300 public static function castZendExtension(\ReflectionZendExtension $c, array $a, Stub $stub, $isNested) | 305 public static function castZendExtension(\ReflectionZendExtension $c, array $a, Stub $stub, $isNested) |
301 { | 306 { |
302 self::addMap($a, $c, array( | 307 self::addMap($a, $c, [ |
303 'version' => 'getVersion', | 308 'version' => 'getVersion', |
304 'author' => 'getAuthor', | 309 'author' => 'getAuthor', |
305 'copyright' => 'getCopyright', | 310 'copyright' => 'getCopyright', |
306 'url' => 'getURL', | 311 'url' => 'getURL', |
307 )); | 312 ]); |
308 | 313 |
309 return $a; | 314 return $a; |
310 } | 315 } |
311 | 316 |
312 private static function addExtra(&$a, \Reflector $c) | 317 private static function addExtra(&$a, \Reflector $c) |
313 { | 318 { |
314 $x = isset($a[Caster::PREFIX_VIRTUAL.'extra']) ? $a[Caster::PREFIX_VIRTUAL.'extra']->value : array(); | 319 $x = isset($a[Caster::PREFIX_VIRTUAL.'extra']) ? $a[Caster::PREFIX_VIRTUAL.'extra']->value : []; |
315 | 320 |
316 if (method_exists($c, 'getFileName') && $m = $c->getFileName()) { | 321 if (method_exists($c, 'getFileName') && $m = $c->getFileName()) { |
317 $x['file'] = new LinkStub($m, $c->getStartLine()); | 322 $x['file'] = new LinkStub($m, $c->getStartLine()); |
318 $x['line'] = $c->getStartLine().' to '.$c->getEndLine(); | 323 $x['line'] = $c->getStartLine().' to '.$c->getEndLine(); |
319 } | 324 } |