<?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; use Symfony\Component\VarDumper\Cloner\Stub; /** * 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 */ public function __construct(string $identifier, callable|array|string $callable = null) { $this->value = $identifier; try { if (null !== $callable) { if ($callable instanceof \Closure) { $r = new \ReflectionFunction($callable); } elseif (\is_object($callable)) { $r = [$callable, '__invoke']; } elseif (\is_array($callable)) { $r = $callable; } elseif (false !== $i = strpos($callable, '::')) { $r = [substr($callable, 0, $i), substr($callable, 2 + $i)]; } else { $r = new \ReflectionFunction($callable); } } elseif (0 < $i = strpos($identifier, '::') ?: strpos($identifier, '->')) { $r = [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) { $r = new \ReflectionClass($r[0]); } } if (str_contains($identifier, "@anonymous\0")) { $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) { return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0]; }, $identifier); } if (null !== $callable && $r instanceof \ReflectionFunctionAbstract) { $s = ReflectionCaster::castFunctionAbstract($r, [], new Stub(), true, Caster::EXCLUDE_VERBOSE); $s = ReflectionCaster::getSignature($s); if (str_ends_with($identifier, '()')) { $this->value = substr_replace($identifier, $s, -2); } else { $this->value .= $s; } } } catch (\ReflectionException) { return; } finally { if (0 < $i = strrpos($this->value, '\\')) { $this->attr['ellipsis'] = \strlen($this->value) - $i; $this->attr['ellipsis-type'] = 'class'; $this->attr['ellipsis-tail'] = 1; } } if ($f = $r->getFileName()) { $this->attr['file'] = $f; $this->attr['line'] = $r->getStartLine(); } } public static function wrapCallable(mixed $callable) { if (\is_object($callable) || !\is_callable($callable)) { return $callable; } if (!\is_array($callable)) { $callable = new static($callable, $callable); } elseif (\is_string($callable[0])) { $callable[0] = new static($callable[0], $callable); } else { $callable[1] = new static($callable[1], $callable); } return $callable; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
AmqpCaster.php | File | 6.54 KB | 0644 |
|
ArgsStub.php | File | 2.24 KB | 0644 |
|
Caster.php | File | 5.85 KB | 0644 |
|
ClassStub.php | File | 3.76 KB | 0644 |
|
ConstStub.php | File | 735 B | 0644 |
|
CutArrayStub.php | File | 696 B | 0644 |
|
CutStub.php | File | 1.88 KB | 0644 |
|
DOMCaster.php | File | 8.81 KB | 0644 |
|
DateCaster.php | File | 4.77 KB | 0644 |
|
DoctrineCaster.php | File | 1.63 KB | 0644 |
|
DsCaster.php | File | 1.55 KB | 0644 |
|
DsPairStub.php | File | 630 B | 0644 |
|
EnumStub.php | File | 637 B | 0644 |
|
ExceptionCaster.php | File | 15.82 KB | 0644 |
|
FFICaster.php | File | 5.17 KB | 0644 |
|
FiberCaster.php | File | 1.04 KB | 0644 |
|
FrameStub.php | File | 740 B | 0644 |
|
GmpCaster.php | File | 749 B | 0644 |
|
ImagineCaster.php | File | 949 B | 0644 |
|
ImgStub.php | File | 637 B | 0644 |
|
IntlCaster.php | File | 8.72 KB | 0644 |
|
LinkStub.php | File | 3.27 KB | 0644 |
|
MemcachedCaster.php | File | 2.23 KB | 0644 |
|
MysqliCaster.php | File | 691 B | 0644 |
|
PdoCaster.php | File | 3.47 KB | 0644 |
|
PgSqlCaster.php | File | 5.36 KB | 0644 |
|
ProxyManagerCaster.php | File | 721 B | 0644 |
|
RdKafkaCaster.php | File | 4.54 KB | 0644 |
|
RedisCaster.php | File | 5.1 KB | 0644 |
|
ReflectionCaster.php | File | 14.66 KB | 0644 |
|
ResourceCaster.php | File | 2.88 KB | 0644 |
|
SplCaster.php | File | 7.23 KB | 0644 |
|
StubCaster.php | File | 2.09 KB | 0644 |
|
SymfonyCaster.php | File | 3.47 KB | 0644 |
|
TraceStub.php | File | 963 B | 0644 |
|
UuidCaster.php | File | 668 B | 0644 |
|
XmlReaderCaster.php | File | 3.22 KB | 0644 |
|
XmlResourceCaster.php | File | 2.49 KB | 0644 |
|