AmqpCaster.php
2 years ago
ArgsStub.php
1 year ago
Caster.php
1 year ago
ClassStub.php
1 year ago
ConstStub.php
2 years ago
CutArrayStub.php
2 years ago
CutStub.php
1 year ago
DOMCaster.php
1 year ago
DateCaster.php
2 years ago
DoctrineCaster.php
2 years ago
DsCaster.php
2 years ago
DsPairStub.php
2 years ago
EnumStub.php
1 year ago
ExceptionCaster.php
1 year ago
FiberCaster.php
2 years ago
FrameStub.php
1 year ago
GmpCaster.php
2 years ago
ImagineCaster.php
2 years ago
ImgStub.php
2 years ago
IntlCaster.php
2 years ago
LinkStub.php
1 year ago
MemcachedCaster.php
2 years ago
MysqliCaster.php
2 years ago
PdoCaster.php
2 years ago
PgSqlCaster.php
1 year ago
ProxyManagerCaster.php
2 years ago
RdKafkaCaster.php
1 year ago
RedisCaster.php
2 years ago
ReflectionCaster.php
1 year ago
ResourceCaster.php
1 year ago
SplCaster.php
1 year ago
StubCaster.php
2 years ago
SymfonyCaster.php
2 years ago
TraceStub.php
1 year ago
UuidCaster.php
2 years ago
XmlReaderCaster.php
1 year ago
XmlResourceCaster.php
2 years ago
ClassStub.php
96 lines
| 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 | namespace Matomo\Dependencies\Symfony\Component\VarDumper\Caster; |
| 12 | |
| 13 | use Matomo\Dependencies\Symfony\Component\VarDumper\Cloner\Stub; |
| 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 $identifier A PHP identifier, e.g. a class, method, interface, etc. name |
| 23 | * @param callable $callable The callable targeted by the identifier when it is ambiguous or not a real PHP identifier |
| 24 | */ |
| 25 | public function __construct(string $identifier, $callable = null) |
| 26 | { |
| 27 | $this->value = $identifier; |
| 28 | try { |
| 29 | if (null !== $callable) { |
| 30 | if ($callable instanceof \Closure) { |
| 31 | $r = new \ReflectionFunction($callable); |
| 32 | } elseif (\is_object($callable)) { |
| 33 | $r = [$callable, '__invoke']; |
| 34 | } elseif (\is_array($callable)) { |
| 35 | $r = $callable; |
| 36 | } elseif (\false !== ($i = strpos($callable, '::'))) { |
| 37 | $r = [substr($callable, 0, $i), substr($callable, 2 + $i)]; |
| 38 | } else { |
| 39 | $r = new \ReflectionFunction($callable); |
| 40 | } |
| 41 | } elseif (0 < ($i = strpos($identifier, '::') ?: strpos($identifier, '->'))) { |
| 42 | $r = [substr($identifier, 0, $i), substr($identifier, 2 + $i)]; |
| 43 | } else { |
| 44 | $r = new \ReflectionClass($identifier); |
| 45 | } |
| 46 | if (\is_array($r)) { |
| 47 | try { |
| 48 | $r = new \ReflectionMethod($r[0], $r[1]); |
| 49 | } catch (\ReflectionException $e) { |
| 50 | $r = new \ReflectionClass($r[0]); |
| 51 | } |
| 52 | } |
| 53 | if (str_contains($identifier, "@anonymous\x00")) { |
| 54 | $this->value = $identifier = preg_replace_callback('/[a-zA-Z_\\x7f-\\xff][\\\\a-zA-Z0-9_\\x7f-\\xff]*+@anonymous\\x00.*?\\.php(?:0x?|:[0-9]++\\$)?[0-9a-fA-F]++/', function ($m) { |
| 55 | return class_exists($m[0], \false) ? ((get_parent_class($m[0]) ?: key(class_implements($m[0]))) ?: 'class') . '@anonymous' : $m[0]; |
| 56 | }, $identifier); |
| 57 | } |
| 58 | if (null !== $callable && $r instanceof \ReflectionFunctionAbstract) { |
| 59 | $s = ReflectionCaster::castFunctionAbstract($r, [], new Stub(), \true, Caster::EXCLUDE_VERBOSE); |
| 60 | $s = ReflectionCaster::getSignature($s); |
| 61 | if (str_ends_with($identifier, '()')) { |
| 62 | $this->value = substr_replace($identifier, $s, -2); |
| 63 | } else { |
| 64 | $this->value .= $s; |
| 65 | } |
| 66 | } |
| 67 | } catch (\ReflectionException $e) { |
| 68 | return; |
| 69 | } finally { |
| 70 | if (0 < ($i = strrpos($this->value, '\\'))) { |
| 71 | $this->attr['ellipsis'] = \strlen($this->value) - $i; |
| 72 | $this->attr['ellipsis-type'] = 'class'; |
| 73 | $this->attr['ellipsis-tail'] = 1; |
| 74 | } |
| 75 | } |
| 76 | if ($f = $r->getFileName()) { |
| 77 | $this->attr['file'] = $f; |
| 78 | $this->attr['line'] = $r->getStartLine(); |
| 79 | } |
| 80 | } |
| 81 | public static function wrapCallable($callable) |
| 82 | { |
| 83 | if (\is_object($callable) || !\is_callable($callable)) { |
| 84 | return $callable; |
| 85 | } |
| 86 | if (!\is_array($callable)) { |
| 87 | $callable = new static($callable, $callable); |
| 88 | } elseif (\is_string($callable[0])) { |
| 89 | $callable[0] = new static($callable[0], $callable); |
| 90 | } else { |
| 91 | $callable[1] = new static($callable[1], $callable); |
| 92 | } |
| 93 | return $callable; |
| 94 | } |
| 95 | } |
| 96 |