comparison vendor/symfony/var-dumper/Caster/ClassStub.php @ 0:c75dbcec494b

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