annotate vendor/symfony/var-dumper/Caster/ClassStub.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\VarDumper\Caster;
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Represents a PHP class identifier.
Chris@0 16 *
Chris@0 17 * @author Nicolas Grekas <p@tchwork.com>
Chris@0 18 */
Chris@0 19 class ClassStub extends ConstStub
Chris@0 20 {
Chris@0 21 /**
Chris@17 22 * @param string $identifier A PHP identifier, e.g. a class, method, interface, etc. name
Chris@17 23 * @param callable $callable The callable targeted by the identifier when it is ambiguous or not a real PHP identifier
Chris@0 24 */
Chris@0 25 public function __construct($identifier, $callable = null)
Chris@0 26 {
Chris@0 27 $this->value = $identifier;
Chris@0 28
Chris@0 29 if (0 < $i = strrpos($identifier, '\\')) {
Chris@17 30 $this->attr['ellipsis'] = \strlen($identifier) - $i;
Chris@0 31 $this->attr['ellipsis-type'] = 'class';
Chris@0 32 $this->attr['ellipsis-tail'] = 1;
Chris@0 33 }
Chris@0 34
Chris@0 35 try {
Chris@0 36 if (null !== $callable) {
Chris@0 37 if ($callable instanceof \Closure) {
Chris@0 38 $r = new \ReflectionFunction($callable);
Chris@17 39 } elseif (\is_object($callable)) {
Chris@17 40 $r = [$callable, '__invoke'];
Chris@17 41 } elseif (\is_array($callable)) {
Chris@0 42 $r = $callable;
Chris@0 43 } elseif (false !== $i = strpos($callable, '::')) {
Chris@17 44 $r = [substr($callable, 0, $i), substr($callable, 2 + $i)];
Chris@0 45 } else {
Chris@0 46 $r = new \ReflectionFunction($callable);
Chris@0 47 }
Chris@0 48 } elseif (0 < $i = strpos($identifier, '::') ?: strpos($identifier, '->')) {
Chris@17 49 $r = [substr($identifier, 0, $i), substr($identifier, 2 + $i)];
Chris@0 50 } else {
Chris@0 51 $r = new \ReflectionClass($identifier);
Chris@0 52 }
Chris@0 53
Chris@17 54 if (\is_array($r)) {
Chris@0 55 try {
Chris@0 56 $r = new \ReflectionMethod($r[0], $r[1]);
Chris@0 57 } catch (\ReflectionException $e) {
Chris@0 58 $r = new \ReflectionClass($r[0]);
Chris@0 59 }
Chris@0 60 }
Chris@0 61 } catch (\ReflectionException $e) {
Chris@0 62 return;
Chris@0 63 }
Chris@0 64
Chris@0 65 if ($f = $r->getFileName()) {
Chris@0 66 $this->attr['file'] = $f;
Chris@0 67 $this->attr['line'] = $r->getStartLine();
Chris@0 68 }
Chris@0 69 }
Chris@0 70
Chris@0 71 public static function wrapCallable($callable)
Chris@0 72 {
Chris@17 73 if (\is_object($callable) || !\is_callable($callable)) {
Chris@0 74 return $callable;
Chris@0 75 }
Chris@0 76
Chris@17 77 if (!\is_array($callable)) {
Chris@0 78 $callable = new static($callable);
Chris@17 79 } elseif (\is_string($callable[0])) {
Chris@0 80 $callable[0] = new static($callable[0]);
Chris@0 81 } else {
Chris@0 82 $callable[1] = new static($callable[1], $callable);
Chris@0 83 }
Chris@0 84
Chris@0 85 return $callable;
Chris@0 86 }
Chris@0 87 }