Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/src/Command/ReflectingCommand.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
54 * | 54 * |
55 * @return array (class or instance name, member name, kind) | 55 * @return array (class or instance name, member name, kind) |
56 */ | 56 */ |
57 protected function getTarget($valueName) | 57 protected function getTarget($valueName) |
58 { | 58 { |
59 $valueName = trim($valueName); | 59 $valueName = \trim($valueName); |
60 $matches = []; | 60 $matches = []; |
61 switch (true) { | 61 switch (true) { |
62 case preg_match(self::CLASS_OR_FUNC, $valueName, $matches): | 62 case \preg_match(self::CLASS_OR_FUNC, $valueName, $matches): |
63 return [$this->resolveName($matches[0], true), null, 0]; | 63 return [$this->resolveName($matches[0], true), null, 0]; |
64 | 64 |
65 case preg_match(self::CLASS_MEMBER, $valueName, $matches): | 65 case \preg_match(self::CLASS_MEMBER, $valueName, $matches): |
66 return [$this->resolveName($matches[1]), $matches[2], Mirror::CONSTANT | Mirror::METHOD]; | 66 return [$this->resolveName($matches[1]), $matches[2], Mirror::CONSTANT | Mirror::METHOD]; |
67 | 67 |
68 case preg_match(self::CLASS_STATIC, $valueName, $matches): | 68 case \preg_match(self::CLASS_STATIC, $valueName, $matches): |
69 return [$this->resolveName($matches[1]), $matches[2], Mirror::STATIC_PROPERTY | Mirror::PROPERTY]; | 69 return [$this->resolveName($matches[1]), $matches[2], Mirror::STATIC_PROPERTY | Mirror::PROPERTY]; |
70 | 70 |
71 case preg_match(self::INSTANCE_MEMBER, $valueName, $matches): | 71 case \preg_match(self::INSTANCE_MEMBER, $valueName, $matches): |
72 if ($matches[2] === '->') { | 72 if ($matches[2] === '->') { |
73 $kind = Mirror::METHOD | Mirror::PROPERTY; | 73 $kind = Mirror::METHOD | Mirror::PROPERTY; |
74 } else { | 74 } else { |
75 $kind = Mirror::CONSTANT | Mirror::METHOD; | 75 $kind = Mirror::CONSTANT | Mirror::METHOD; |
76 } | 76 } |
95 protected function resolveName($name, $includeFunctions = false) | 95 protected function resolveName($name, $includeFunctions = false) |
96 { | 96 { |
97 $shell = $this->getApplication(); | 97 $shell = $this->getApplication(); |
98 | 98 |
99 // While not *technically* 100% accurate, let's treat `self` and `static` as equivalent. | 99 // While not *technically* 100% accurate, let's treat `self` and `static` as equivalent. |
100 if (in_array(strtolower($name), ['self', 'static'])) { | 100 if (\in_array(\strtolower($name), ['self', 'static'])) { |
101 if ($boundClass = $shell->getBoundClass()) { | 101 if ($boundClass = $shell->getBoundClass()) { |
102 return $boundClass; | 102 return $boundClass; |
103 } | 103 } |
104 | 104 |
105 if ($boundObject = $shell->getBoundObject()) { | 105 if ($boundObject = $shell->getBoundObject()) { |
106 return get_class($boundObject); | 106 return \get_class($boundObject); |
107 } | 107 } |
108 | 108 |
109 $msg = sprintf('Cannot use "%s" when no class scope is active', strtolower($name)); | 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); | 110 throw new ErrorException($msg, 0, E_USER_ERROR, "eval()'d code", 1); |
111 } | 111 } |
112 | 112 |
113 if (substr($name, 0, 1) === '\\') { | 113 if (\substr($name, 0, 1) === '\\') { |
114 return $name; | 114 return $name; |
115 } | 115 } |
116 | 116 |
117 if ($namespace = $shell->getNamespace()) { | 117 if ($namespace = $shell->getNamespace()) { |
118 $fullName = $namespace . '\\' . $name; | 118 $fullName = $namespace . '\\' . $name; |
119 | 119 |
120 if (class_exists($fullName) || interface_exists($fullName) || ($includeFunctions && function_exists($fullName))) { | 120 if (\class_exists($fullName) || \interface_exists($fullName) || ($includeFunctions && \function_exists($fullName))) { |
121 return $fullName; | 121 return $fullName; |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 return $name; | 125 return $name; |
174 */ | 174 */ |
175 private function resolveObject($code) | 175 private function resolveObject($code) |
176 { | 176 { |
177 $value = $this->resolveCode($code); | 177 $value = $this->resolveCode($code); |
178 | 178 |
179 if (!is_object($value)) { | 179 if (!\is_object($value)) { |
180 throw new RuntimeException('Unable to inspect a non-object'); | 180 throw new RuntimeException('Unable to inspect a non-object'); |
181 } | 181 } |
182 | 182 |
183 return $value; | 183 return $value; |
184 } | 184 } |
190 * | 190 * |
191 * @return mixed Variable instance | 191 * @return mixed Variable instance |
192 */ | 192 */ |
193 protected function resolveInstance($name) | 193 protected function resolveInstance($name) |
194 { | 194 { |
195 @trigger_error('`resolveInstance` is deprecated; use `resolveCode` instead.', E_USER_DEPRECATED); | 195 @\trigger_error('`resolveInstance` is deprecated; use `resolveCode` instead.', E_USER_DEPRECATED); |
196 | 196 |
197 return $this->resolveCode($name); | 197 return $this->resolveCode($name); |
198 } | 198 } |
199 | 199 |
200 /** | 200 /** |
228 */ | 228 */ |
229 protected function setCommandScopeVariables(\Reflector $reflector) | 229 protected function setCommandScopeVariables(\Reflector $reflector) |
230 { | 230 { |
231 $vars = []; | 231 $vars = []; |
232 | 232 |
233 switch (get_class($reflector)) { | 233 switch (\get_class($reflector)) { |
234 case 'ReflectionClass': | 234 case 'ReflectionClass': |
235 case 'ReflectionObject': | 235 case 'ReflectionObject': |
236 $vars['__class'] = $reflector->name; | 236 $vars['__class'] = $reflector->name; |
237 if ($reflector->inNamespace()) { | 237 if ($reflector->inNamespace()) { |
238 $vars['__namespace'] = $reflector->getNamespaceName(); | 238 $vars['__namespace'] = $reflector->getNamespaceName(); |
239 } | 239 } |
240 break; | 240 break; |
241 | 241 |
242 case 'ReflectionMethod': | 242 case 'ReflectionMethod': |
243 $vars['__method'] = sprintf('%s::%s', $reflector->class, $reflector->name); | 243 $vars['__method'] = \sprintf('%s::%s', $reflector->class, $reflector->name); |
244 $vars['__class'] = $reflector->class; | 244 $vars['__class'] = $reflector->class; |
245 $classReflector = $reflector->getDeclaringClass(); | 245 $classReflector = $reflector->getDeclaringClass(); |
246 if ($classReflector->inNamespace()) { | 246 if ($classReflector->inNamespace()) { |
247 $vars['__namespace'] = $classReflector->getNamespaceName(); | 247 $vars['__namespace'] = $classReflector->getNamespaceName(); |
248 } | 248 } |
262 $vars['__namespace'] = $funcReflector->getNamespaceName(); | 262 $vars['__namespace'] = $funcReflector->getNamespaceName(); |
263 } | 263 } |
264 if ($fileName = $reflector->getExecutingFile()) { | 264 if ($fileName = $reflector->getExecutingFile()) { |
265 $vars['__file'] = $fileName; | 265 $vars['__file'] = $fileName; |
266 $vars['__line'] = $reflector->getExecutingLine(); | 266 $vars['__line'] = $reflector->getExecutingLine(); |
267 $vars['__dir'] = dirname($fileName); | 267 $vars['__dir'] = \dirname($fileName); |
268 } | 268 } |
269 break; | 269 break; |
270 | 270 |
271 case 'ReflectionProperty': | 271 case 'ReflectionProperty': |
272 case 'ReflectionClassConstant': | 272 case 'ReflectionClassConstant': |
277 $vars['__namespace'] = $classReflector->getNamespaceName(); | 277 $vars['__namespace'] = $classReflector->getNamespaceName(); |
278 } | 278 } |
279 // no line for these, but this'll do | 279 // no line for these, but this'll do |
280 if ($fileName = $reflector->getDeclaringClass()->getFileName()) { | 280 if ($fileName = $reflector->getDeclaringClass()->getFileName()) { |
281 $vars['__file'] = $fileName; | 281 $vars['__file'] = $fileName; |
282 $vars['__dir'] = dirname($fileName); | 282 $vars['__dir'] = \dirname($fileName); |
283 } | 283 } |
284 break; | 284 break; |
285 | 285 |
286 case 'Psy\Reflection\ReflectionConstant_': | 286 case 'Psy\Reflection\ReflectionConstant_': |
287 if ($reflector->inNamespace()) { | 287 if ($reflector->inNamespace()) { |
292 | 292 |
293 if ($reflector instanceof \ReflectionClass || $reflector instanceof \ReflectionFunctionAbstract) { | 293 if ($reflector instanceof \ReflectionClass || $reflector instanceof \ReflectionFunctionAbstract) { |
294 if ($fileName = $reflector->getFileName()) { | 294 if ($fileName = $reflector->getFileName()) { |
295 $vars['__file'] = $fileName; | 295 $vars['__file'] = $fileName; |
296 $vars['__line'] = $reflector->getStartLine(); | 296 $vars['__line'] = $reflector->getStartLine(); |
297 $vars['__dir'] = dirname($fileName); | 297 $vars['__dir'] = \dirname($fileName); |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 $this->context->setCommandScopeVariables($vars); | 301 $this->context->setCommandScopeVariables($vars); |
302 } | 302 } |