Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/src/Command/ReflectingCommand.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | 5fb285c0d0e3 |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
15:e200cb7efeb3 | 16:c2387f117808 |
---|---|
12 namespace Psy\Command; | 12 namespace Psy\Command; |
13 | 13 |
14 use Psy\CodeCleaner\NoReturnValue; | 14 use Psy\CodeCleaner\NoReturnValue; |
15 use Psy\Context; | 15 use Psy\Context; |
16 use Psy\ContextAware; | 16 use Psy\ContextAware; |
17 use Psy\Exception\ErrorException; | |
17 use Psy\Exception\RuntimeException; | 18 use Psy\Exception\RuntimeException; |
18 use Psy\Util\Mirror; | 19 use Psy\Util\Mirror; |
19 | 20 |
20 /** | 21 /** |
21 * An abstract command with helpers for inspecting the current context. | 22 * An abstract command with helpers for inspecting the current context. |
82 } | 83 } |
83 | 84 |
84 /** | 85 /** |
85 * Resolve a class or function name (with the current shell namespace). | 86 * Resolve a class or function name (with the current shell namespace). |
86 * | 87 * |
88 * @throws ErrorException when `self` or `static` is used in a non-class scope | |
89 * | |
87 * @param string $name | 90 * @param string $name |
88 * @param bool $includeFunctions (default: false) | 91 * @param bool $includeFunctions (default: false) |
89 * | 92 * |
90 * @return string | 93 * @return string |
91 */ | 94 */ |
92 protected function resolveName($name, $includeFunctions = false) | 95 protected function resolveName($name, $includeFunctions = false) |
93 { | 96 { |
97 $shell = $this->getApplication(); | |
98 | |
99 // While not *technically* 100% accurate, let's treat `self` and `static` as equivalent. | |
100 if (in_array(strtolower($name), ['self', 'static'])) { | |
101 if ($boundClass = $shell->getBoundClass()) { | |
102 return $boundClass; | |
103 } | |
104 | |
105 if ($boundObject = $shell->getBoundObject()) { | |
106 return get_class($boundObject); | |
107 } | |
108 | |
109 $msg = sprintf('Cannot use "%s" when no class scope is active', strtolower($name)); | |
110 throw new ErrorException($msg, 0, E_USER_ERROR, "eval()'d code", 1); | |
111 } | |
112 | |
94 if (substr($name, 0, 1) === '\\') { | 113 if (substr($name, 0, 1) === '\\') { |
95 return $name; | 114 return $name; |
96 } | 115 } |
97 | 116 |
98 if ($namespace = $this->getApplication()->getNamespace()) { | 117 if ($namespace = $shell->getNamespace()) { |
99 $fullName = $namespace . '\\' . $name; | 118 $fullName = $namespace . '\\' . $name; |
100 | 119 |
101 if (class_exists($fullName) || interface_exists($fullName) || ($includeFunctions && function_exists($fullName))) { | 120 if (class_exists($fullName) || interface_exists($fullName) || ($includeFunctions && function_exists($fullName))) { |
102 return $fullName; | 121 return $fullName; |
103 } | 122 } |
248 $vars['__dir'] = dirname($fileName); | 267 $vars['__dir'] = dirname($fileName); |
249 } | 268 } |
250 break; | 269 break; |
251 | 270 |
252 case 'ReflectionProperty': | 271 case 'ReflectionProperty': |
253 case 'Psy\Reflection\ReflectionConstant': | 272 case 'ReflectionClassConstant': |
273 case 'Psy\Reflection\ReflectionClassConstant': | |
254 $classReflector = $reflector->getDeclaringClass(); | 274 $classReflector = $reflector->getDeclaringClass(); |
255 $vars['__class'] = $classReflector->name; | 275 $vars['__class'] = $classReflector->name; |
256 if ($classReflector->inNamespace()) { | 276 if ($classReflector->inNamespace()) { |
257 $vars['__namespace'] = $classReflector->getNamespaceName(); | 277 $vars['__namespace'] = $classReflector->getNamespaceName(); |
258 } | 278 } |
259 // no line for these, but this'll do | 279 // no line for these, but this'll do |
260 if ($fileName = $reflector->getDeclaringClass()->getFileName()) { | 280 if ($fileName = $reflector->getDeclaringClass()->getFileName()) { |
261 $vars['__file'] = $fileName; | 281 $vars['__file'] = $fileName; |
262 $vars['__dir'] = dirname($fileName); | 282 $vars['__dir'] = dirname($fileName); |
283 } | |
284 break; | |
285 | |
286 case 'Psy\Reflection\ReflectionConstant_': | |
287 if ($reflector->inNamespace()) { | |
288 $vars['__namespace'] = $reflector->getNamespaceName(); | |
263 } | 289 } |
264 break; | 290 break; |
265 } | 291 } |
266 | 292 |
267 if ($reflector instanceof \ReflectionClass || $reflector instanceof \ReflectionFunctionAbstract) { | 293 if ($reflector instanceof \ReflectionClass || $reflector instanceof \ReflectionFunctionAbstract) { |