comparison vendor/symfony/var-dumper/Caster/ClassStub.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
17 * @author Nicolas Grekas <p@tchwork.com> 17 * @author Nicolas Grekas <p@tchwork.com>
18 */ 18 */
19 class ClassStub extends ConstStub 19 class ClassStub extends ConstStub
20 { 20 {
21 /** 21 /**
22 * @param string A PHP identifier, e.g. a class, method, interface, etc. name 22 * @param string $identifier 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 23 * @param callable $callable The callable targeted by the identifier when it is ambiguous or not a real PHP identifier
24 */ 24 */
25 public function __construct($identifier, $callable = null) 25 public function __construct($identifier, $callable = null)
26 { 26 {
27 $this->value = $identifier; 27 $this->value = $identifier;
28 28
29 if (0 < $i = strrpos($identifier, '\\')) { 29 if (0 < $i = strrpos($identifier, '\\')) {
30 $this->attr['ellipsis'] = strlen($identifier) - $i; 30 $this->attr['ellipsis'] = \strlen($identifier) - $i;
31 $this->attr['ellipsis-type'] = 'class'; 31 $this->attr['ellipsis-type'] = 'class';
32 $this->attr['ellipsis-tail'] = 1; 32 $this->attr['ellipsis-tail'] = 1;
33 } 33 }
34 34
35 try { 35 try {
36 if (null !== $callable) { 36 if (null !== $callable) {
37 if ($callable instanceof \Closure) { 37 if ($callable instanceof \Closure) {
38 $r = new \ReflectionFunction($callable); 38 $r = new \ReflectionFunction($callable);
39 } elseif (is_object($callable)) { 39 } elseif (\is_object($callable)) {
40 $r = array($callable, '__invoke'); 40 $r = [$callable, '__invoke'];
41 } elseif (is_array($callable)) { 41 } elseif (\is_array($callable)) {
42 $r = $callable; 42 $r = $callable;
43 } elseif (false !== $i = strpos($callable, '::')) { 43 } elseif (false !== $i = strpos($callable, '::')) {
44 $r = array(substr($callable, 0, $i), substr($callable, 2 + $i)); 44 $r = [substr($callable, 0, $i), substr($callable, 2 + $i)];
45 } else { 45 } else {
46 $r = new \ReflectionFunction($callable); 46 $r = new \ReflectionFunction($callable);
47 } 47 }
48 } elseif (0 < $i = strpos($identifier, '::') ?: strpos($identifier, '->')) { 48 } elseif (0 < $i = strpos($identifier, '::') ?: strpos($identifier, '->')) {
49 $r = array(substr($identifier, 0, $i), substr($identifier, 2 + $i)); 49 $r = [substr($identifier, 0, $i), substr($identifier, 2 + $i)];
50 } else { 50 } else {
51 $r = new \ReflectionClass($identifier); 51 $r = new \ReflectionClass($identifier);
52 } 52 }
53 53
54 if (is_array($r)) { 54 if (\is_array($r)) {
55 try { 55 try {
56 $r = new \ReflectionMethod($r[0], $r[1]); 56 $r = new \ReflectionMethod($r[0], $r[1]);
57 } catch (\ReflectionException $e) { 57 } catch (\ReflectionException $e) {
58 $r = new \ReflectionClass($r[0]); 58 $r = new \ReflectionClass($r[0]);
59 } 59 }
68 } 68 }
69 } 69 }
70 70
71 public static function wrapCallable($callable) 71 public static function wrapCallable($callable)
72 { 72 {
73 if (is_object($callable) || !is_callable($callable)) { 73 if (\is_object($callable) || !\is_callable($callable)) {
74 return $callable; 74 return $callable;
75 } 75 }
76 76
77 if (!is_array($callable)) { 77 if (!\is_array($callable)) {
78 $callable = new static($callable); 78 $callable = new static($callable);
79 } elseif (is_string($callable[0])) { 79 } elseif (\is_string($callable[0])) {
80 $callable[0] = new static($callable[0]); 80 $callable[0] = new static($callable[0]);
81 } else { 81 } else {
82 $callable[1] = new static($callable[1], $callable); 82 $callable[1] = new static($callable[1], $callable);
83 } 83 }
84 84