Blame view

vendor/symfony/var-dumper/Caster/ClassStub.php 2.74 KB
c4650843   Etienne Pallier   Ajout du dossier ...
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\VarDumper\Caster;

c4650843   Etienne Pallier   Ajout du dossier ...
14
15
16
17
18
19
20
21
22
23
24
/**
 * Represents a PHP class identifier.
 *
 * @author Nicolas Grekas <p@tchwork.com>
 */
class ClassStub extends ConstStub
{
    /**
     * @param string   $identifier A PHP identifier, e.g. a class, method, interface, etc. name
     * @param callable $callable   The callable targeted by the identifier when it is ambiguous or not a real PHP identifier
     */
d06254b2   Etienne Pallier   bugfix plugin mig...
25
    public function __construct($identifier, $callable = null)
c4650843   Etienne Pallier   Ajout du dossier ...
26
27
28
    {
        $this->value = $identifier;

d06254b2   Etienne Pallier   bugfix plugin mig...
29
30
31
32
33
34
        if (0 < $i = strrpos($identifier, '\\')) {
            $this->attr['ellipsis'] = \strlen($identifier) - $i;
            $this->attr['ellipsis-type'] = 'class';
            $this->attr['ellipsis-tail'] = 1;
        }

c4650843   Etienne Pallier   Ajout du dossier ...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
        try {
            if (null !== $callable) {
                if ($callable instanceof \Closure) {
                    $r = new \ReflectionFunction($callable);
                } elseif (\is_object($callable)) {
                    $r = array($callable, '__invoke');
                } elseif (\is_array($callable)) {
                    $r = $callable;
                } elseif (false !== $i = strpos($callable, '::')) {
                    $r = array(substr($callable, 0, $i), substr($callable, 2 + $i));
                } else {
                    $r = new \ReflectionFunction($callable);
                }
            } elseif (0 < $i = strpos($identifier, '::') ?: strpos($identifier, '->')) {
                $r = array(substr($identifier, 0, $i), substr($identifier, 2 + $i));
            } else {
                $r = new \ReflectionClass($identifier);
            }

            if (\is_array($r)) {
                try {
                    $r = new \ReflectionMethod($r[0], $r[1]);
                } catch (\ReflectionException $e) {
                    $r = new \ReflectionClass($r[0]);
                }
            }
c4650843   Etienne Pallier   Ajout du dossier ...
61
62
        } catch (\ReflectionException $e) {
            return;
c4650843   Etienne Pallier   Ajout du dossier ...
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        }

        if ($f = $r->getFileName()) {
            $this->attr['file'] = $f;
            $this->attr['line'] = $r->getStartLine();
        }
    }

    public static function wrapCallable($callable)
    {
        if (\is_object($callable) || !\is_callable($callable)) {
            return $callable;
        }

        if (!\is_array($callable)) {
d06254b2   Etienne Pallier   bugfix plugin mig...
78
            $callable = new static($callable);
c4650843   Etienne Pallier   Ajout du dossier ...
79
        } elseif (\is_string($callable[0])) {
d06254b2   Etienne Pallier   bugfix plugin mig...
80
            $callable[0] = new static($callable[0]);
c4650843   Etienne Pallier   Ajout du dossier ...
81
82
83
84
85
86
87
        } else {
            $callable[1] = new static($callable[1], $callable);
        }

        return $callable;
    }
}