Mercurial > hg > isophonics-drupal-site
diff 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 |
line wrap: on
line diff
--- a/vendor/psy/psysh/src/Command/ReflectingCommand.php Thu Apr 26 11:26:54 2018 +0100 +++ b/vendor/psy/psysh/src/Command/ReflectingCommand.php Tue Jul 10 15:07:59 2018 +0100 @@ -14,6 +14,7 @@ use Psy\CodeCleaner\NoReturnValue; use Psy\Context; use Psy\ContextAware; +use Psy\Exception\ErrorException; use Psy\Exception\RuntimeException; use Psy\Util\Mirror; @@ -84,6 +85,8 @@ /** * Resolve a class or function name (with the current shell namespace). * + * @throws ErrorException when `self` or `static` is used in a non-class scope + * * @param string $name * @param bool $includeFunctions (default: false) * @@ -91,11 +94,27 @@ */ protected function resolveName($name, $includeFunctions = false) { + $shell = $this->getApplication(); + + // While not *technically* 100% accurate, let's treat `self` and `static` as equivalent. + if (in_array(strtolower($name), ['self', 'static'])) { + if ($boundClass = $shell->getBoundClass()) { + return $boundClass; + } + + if ($boundObject = $shell->getBoundObject()) { + return get_class($boundObject); + } + + $msg = sprintf('Cannot use "%s" when no class scope is active', strtolower($name)); + throw new ErrorException($msg, 0, E_USER_ERROR, "eval()'d code", 1); + } + if (substr($name, 0, 1) === '\\') { return $name; } - if ($namespace = $this->getApplication()->getNamespace()) { + if ($namespace = $shell->getNamespace()) { $fullName = $namespace . '\\' . $name; if (class_exists($fullName) || interface_exists($fullName) || ($includeFunctions && function_exists($fullName))) { @@ -250,7 +269,8 @@ break; case 'ReflectionProperty': - case 'Psy\Reflection\ReflectionConstant': + case 'ReflectionClassConstant': + case 'Psy\Reflection\ReflectionClassConstant': $classReflector = $reflector->getDeclaringClass(); $vars['__class'] = $classReflector->name; if ($classReflector->inNamespace()) { @@ -262,6 +282,12 @@ $vars['__dir'] = dirname($fileName); } break; + + case 'Psy\Reflection\ReflectionConstant_': + if ($reflector->inNamespace()) { + $vars['__namespace'] = $reflector->getNamespaceName(); + } + break; } if ($reflector instanceof \ReflectionClass || $reflector instanceof \ReflectionFunctionAbstract) {