N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)

* Update Symfony lib to version ~6.4.0
* Update code missing return type
* Add an iTop general configuration entry to store application secret (Symfony mandatory parameter)
* Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
bdalsass
2023-12-05 13:56:56 +01:00
committed by GitHub
parent 863ab4560c
commit 27ce51ab07
1392 changed files with 44869 additions and 27799 deletions

View File

@@ -46,6 +46,9 @@ class AmqpCaster
\AMQP_EX_TYPE_HEADERS => 'AMQP_EX_TYPE_HEADERS',
];
/**
* @return array
*/
public static function castConnection(\AMQPConnection $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -79,6 +82,9 @@ class AmqpCaster
return $a;
}
/**
* @return array
*/
public static function castChannel(\AMQPChannel $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -102,6 +108,9 @@ class AmqpCaster
return $a;
}
/**
* @return array
*/
public static function castQueue(\AMQPQueue $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -125,6 +134,9 @@ class AmqpCaster
return $a;
}
/**
* @return array
*/
public static function castExchange(\AMQPExchange $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -153,6 +165,9 @@ class AmqpCaster
return $a;
}
/**
* @return array
*/
public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$prefix = Caster::PREFIX_VIRTUAL;

View File

@@ -20,7 +20,7 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class ArgsStub extends EnumStub
{
private static $parameters = [];
private static array $parameters = [];
public function __construct(array $args, string $function, ?string $class)
{
@@ -57,7 +57,7 @@ class ArgsStub extends EnumStub
try {
$r = null !== $class ? new \ReflectionMethod($class, $function) : new \ReflectionFunction($function);
} catch (\ReflectionException $e) {
} catch (\ReflectionException) {
return [null, null];
}

View File

@@ -32,10 +32,15 @@ class Caster
public const EXCLUDE_EMPTY = 128;
public const EXCLUDE_NOT_IMPORTANT = 256;
public const EXCLUDE_STRICT = 512;
public const EXCLUDE_UNINITIALIZED = 1024;
public const PREFIX_VIRTUAL = "\0~\0";
public const PREFIX_DYNAMIC = "\0+\0";
public const PREFIX_PROTECTED = "\0*\0";
// usage: sprintf(Caster::PATTERN_PRIVATE, $class, $property)
public const PATTERN_PRIVATE = "\0%s\0%s";
private static array $classProperties = [];
/**
* Casts objects to arrays and adds the dynamic property prefix.
@@ -47,7 +52,7 @@ class Caster
if ($hasDebugInfo) {
try {
$debugInfo = $obj->__debugInfo();
} catch (\Exception $e) {
} catch (\Throwable) {
// ignore failing __debugInfo()
$hasDebugInfo = false;
}
@@ -59,20 +64,17 @@ class Caster
return $a;
}
$classProperties = self::$classProperties[$class] ??= self::getClassProperties(new \ReflectionClass($class));
$a = array_replace($classProperties, $a);
if ($a) {
static $publicProperties = [];
$debugClass = $debugClass ?? get_debug_type($obj);
$debugClass ??= get_debug_type($obj);
$i = 0;
$prefixedKeys = [];
foreach ($a as $k => $v) {
if ("\0" !== ($k[0] ?? '')) {
if (!isset($publicProperties[$class])) {
foreach ((new \ReflectionClass($class))->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
$publicProperties[$class][$prop->name] = true;
}
}
if (!isset($publicProperties[$class][$k])) {
if (!isset($classProperties[$k])) {
$prefixedKeys[$i] = self::PREFIX_DYNAMIC.$k;
}
} elseif ($debugClass !== $class && 1 === strpos($k, $class)) {
@@ -115,7 +117,7 @@ class Caster
* @param array $a The array containing the properties to filter
* @param int $filter A bit field of Caster::EXCLUDE_* constants specifying which properties to filter out
* @param string[] $listedProperties List of properties to exclude when Caster::EXCLUDE_VERBOSE is set, and to preserve when Caster::EXCLUDE_NOT_IMPORTANT is set
* @param int &$count Set to the number of removed properties
* @param int|null &$count Set to the number of removed properties
*/
public static function filter(array $a, int $filter, array $listedProperties = [], ?int &$count = 0): array
{
@@ -129,6 +131,8 @@ class Caster
$type |= self::EXCLUDE_EMPTY & $filter;
} elseif (false === $v || '' === $v || '0' === $v || 0 === $v || 0.0 === $v || [] === $v) {
$type |= self::EXCLUDE_EMPTY & $filter;
} elseif ($v instanceof UninitializedStub) {
$type |= self::EXCLUDE_UNINITIALIZED & $filter;
}
if ((self::EXCLUDE_NOT_IMPORTANT & $filter) && !\in_array($k, $listedProperties, true)) {
$type |= self::EXCLUDE_NOT_IMPORTANT;
@@ -167,4 +171,28 @@ class Caster
return $a;
}
private static function getClassProperties(\ReflectionClass $class): array
{
$classProperties = [];
$className = $class->name;
if ($parent = $class->getParentClass()) {
$classProperties += self::$classProperties[$parent->name] ??= self::getClassProperties($parent);
}
foreach ($class->getProperties() as $p) {
if ($p->isStatic()) {
continue;
}
$classProperties[match (true) {
$p->isPublic() => $p->name,
$p->isProtected() => self::PREFIX_PROTECTED.$p->name,
default => "\0".$className."\0".$p->name,
}] = new UninitializedStub($p);
}
return $classProperties;
}
}

View File

@@ -24,7 +24,7 @@ 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 = null)
public function __construct(string $identifier, callable|array|string $callable = null)
{
$this->value = $identifier;
@@ -50,15 +50,13 @@ class ClassStub extends ConstStub
if (\is_array($r)) {
try {
$r = new \ReflectionMethod($r[0], $r[1]);
} catch (\ReflectionException $e) {
} 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);
$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]++/', fn ($m) => 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) {
@@ -71,7 +69,7 @@ class ClassStub extends ConstStub
$this->value .= $s;
}
}
} catch (\ReflectionException $e) {
} catch (\ReflectionException) {
return;
} finally {
if (0 < $i = strrpos($this->value, '\\')) {
@@ -87,7 +85,10 @@ class ClassStub extends ConstStub
}
}
public static function wrapCallable($callable)
/**
* @return mixed
*/
public static function wrapCallable(mixed $callable)
{
if (\is_object($callable) || !\is_callable($callable)) {
return $callable;

View File

@@ -20,16 +20,13 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class ConstStub extends Stub
{
public function __construct(string $name, $value = null)
public function __construct(string $name, string|int|float $value = null)
{
$this->class = $name;
$this->value = 1 < \func_num_args() ? $value : $name;
}
/**
* @return string
*/
public function __toString()
public function __toString(): string
{
return (string) $this->value;
}

View File

@@ -20,14 +20,14 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class CutStub extends Stub
{
public function __construct($value)
public function __construct(mixed $value)
{
$this->value = $value;
switch (\gettype($value)) {
case 'object':
$this->type = self::TYPE_OBJECT;
$this->class = \get_class($value);
$this->class = $value::class;
if ($value instanceof \Closure) {
ReflectionCaster::castClosure($value, [], $this, true, Caster::EXCLUDE_VERBOSE);

View File

@@ -63,6 +63,9 @@ class DOMCaster
\XML_NAMESPACE_DECL_NODE => 'XML_NAMESPACE_DECL_NODE',
];
/**
* @return array
*/
public static function castException(\DOMException $e, array $a, Stub $stub, bool $isNested)
{
$k = Caster::PREFIX_PROTECTED.'code';
@@ -73,6 +76,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castLength($dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -82,6 +88,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castImplementation(\DOMImplementation $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -92,6 +101,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castNode(\DOMNode $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -116,6 +128,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -132,6 +147,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$a += [
@@ -166,6 +184,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castCharacterData(\DOMCharacterData $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -176,6 +197,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castAttr(\DOMAttr $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -189,6 +213,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castElement(\DOMElement $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -199,6 +226,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castText(\DOMText $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -208,43 +238,9 @@ class DOMCaster
return $a;
}
public static function castTypeinfo(\DOMTypeinfo $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'typeName' => $dom->typeName,
'typeNamespace' => $dom->typeNamespace,
];
return $a;
}
public static function castDomError(\DOMDomError $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'severity' => $dom->severity,
'message' => $dom->message,
'type' => $dom->type,
'relatedException' => $dom->relatedException,
'related_data' => $dom->related_data,
'location' => $dom->location,
];
return $a;
}
public static function castLocator(\DOMLocator $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
'lineNumber' => $dom->lineNumber,
'columnNumber' => $dom->columnNumber,
'offset' => $dom->offset,
'relatedNode' => $dom->relatedNode,
'uri' => $dom->uri ? new LinkStub($dom->uri, $dom->lineNumber) : $dom->uri,
];
return $a;
}
/**
* @return array
*/
public static function castDocumentType(\DOMDocumentType $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -259,6 +255,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castNotation(\DOMNotation $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -269,6 +268,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castEntity(\DOMEntity $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -283,6 +285,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castProcessingInstruction(\DOMProcessingInstruction $dom, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -293,6 +298,9 @@ class DOMCaster
return $a;
}
/**
* @return array
*/
public static function castXPath(\DOMXPath $dom, array $a, Stub $stub, bool $isNested)
{
$a += [

View File

@@ -24,11 +24,14 @@ class DateCaster
{
private const PERIOD_LIMIT = 3;
/**
* @return array
*/
public static function castDateTime(\DateTimeInterface $d, array $a, Stub $stub, bool $isNested, int $filter)
{
$prefix = Caster::PREFIX_VIRTUAL;
$location = $d->getTimezone()->getLocation();
$fromNow = (new \DateTime())->diff($d);
$location = $d->getTimezone() ? $d->getTimezone()->getLocation() : null;
$fromNow = (new \DateTimeImmutable())->diff($d);
$title = $d->format('l, F j, Y')
."\n".self::formatInterval($fromNow).' from now'
@@ -47,6 +50,9 @@ class DateCaster
return $a;
}
/**
* @return array
*/
public static function castInterval(\DateInterval $interval, array $a, Stub $stub, bool $isNested, int $filter)
{
$now = new \DateTimeImmutable('@0', new \DateTimeZone('UTC'));
@@ -76,10 +82,13 @@ class DateCaster
return $i->format(rtrim($format));
}
/**
* @return array
*/
public static function castTimeZone(\DateTimeZone $timeZone, array $a, Stub $stub, bool $isNested, int $filter)
{
$location = $timeZone->getLocation();
$formatted = (new \DateTime('now', $timeZone))->format($location ? 'e (P)' : 'P');
$formatted = (new \DateTimeImmutable('now', $timeZone))->format($location ? 'e (P)' : 'P');
$title = $location && \extension_loaded('intl') ? \Locale::getDisplayRegion('-'.$location['country_code']) : '';
$z = [Caster::PREFIX_VIRTUAL.'timezone' => new ConstStub($formatted, $title)];
@@ -87,6 +96,9 @@ class DateCaster
return $filter & Caster::EXCLUDE_VERBOSE ? $z : $z + $a;
}
/**
* @return array
*/
public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, bool $isNested, int $filter)
{
$dates = [];

View File

@@ -25,6 +25,9 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class DoctrineCaster
{
/**
* @return array
*/
public static function castCommonProxy(CommonProxy $proxy, array $a, Stub $stub, bool $isNested)
{
foreach (['__cloner__', '__initializer__'] as $k) {
@@ -37,6 +40,9 @@ class DoctrineCaster
return $a;
}
/**
* @return array
*/
public static function castOrmProxy(OrmProxy $proxy, array $a, Stub $stub, bool $isNested)
{
foreach (['_entityPersister', '_identifier'] as $k) {
@@ -49,6 +55,9 @@ class DoctrineCaster
return $a;
}
/**
* @return array
*/
public static function castPersistentCollection(PersistentCollection $coll, array $a, Stub $stub, bool $isNested)
{
foreach (['snapshot', 'association', 'typeClass'] as $k) {

View File

@@ -18,7 +18,7 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class DsPairStub extends Stub
{
public function __construct($key, $value)
public function __construct(mixed $key, mixed $value)
{
$this->value = [
Caster::PREFIX_VIRTUAL.'key' => $key,

View File

@@ -11,6 +11,7 @@
namespace Symfony\Component\VarDumper\Caster;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\ErrorHandler\Exception\SilencedErrorContext;
use Symfony\Component\VarDumper\Cloner\Stub;
use Symfony\Component\VarDumper\Exception\ThrowingCasterException;
@@ -24,9 +25,9 @@ use Symfony\Component\VarDumper\Exception\ThrowingCasterException;
*/
class ExceptionCaster
{
public static $srcContext = 1;
public static $traceArgs = true;
public static $errorTypes = [
public static int $srcContext = 1;
public static bool $traceArgs = true;
public static array $errorTypes = [
\E_DEPRECATED => 'E_DEPRECATED',
\E_USER_DEPRECATED => 'E_USER_DEPRECATED',
\E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
@@ -44,18 +45,27 @@ class ExceptionCaster
\E_STRICT => 'E_STRICT',
];
private static $framesCache = [];
private static array $framesCache = [];
/**
* @return array
*/
public static function castError(\Error $e, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
return self::filterExceptionArray($stub->class, $a, "\0Error\0", $filter);
}
/**
* @return array
*/
public static function castException(\Exception $e, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
return self::filterExceptionArray($stub->class, $a, "\0Exception\0", $filter);
}
/**
* @return array
*/
public static function castErrorException(\ErrorException $e, array $a, Stub $stub, bool $isNested)
{
if (isset($a[$s = Caster::PREFIX_PROTECTED.'severity'], self::$errorTypes[$a[$s]])) {
@@ -65,6 +75,9 @@ class ExceptionCaster
return $a;
}
/**
* @return array
*/
public static function castThrowingCasterException(ThrowingCasterException $e, array $a, Stub $stub, bool $isNested)
{
$trace = Caster::PREFIX_VIRTUAL.'trace';
@@ -83,6 +96,9 @@ class ExceptionCaster
return $a;
}
/**
* @return array
*/
public static function castSilencedErrorContext(SilencedErrorContext $e, array $a, Stub $stub, bool $isNested)
{
$sPrefix = "\0".SilencedErrorContext::class."\0";
@@ -110,6 +126,9 @@ class ExceptionCaster
return $a;
}
/**
* @return array
*/
public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, bool $isNested)
{
if (!$isNested) {
@@ -184,6 +203,9 @@ class ExceptionCaster
return $a;
}
/**
* @return array
*/
public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, bool $isNested)
{
if (!$isNested) {
@@ -267,6 +289,19 @@ class ExceptionCaster
return $a;
}
/**
* @return array
*/
public static function castFlattenException(FlattenException $e, array $a, Stub $stub, bool $isNested)
{
if ($isNested) {
$k = sprintf(Caster::PATTERN_PRIVATE, FlattenException::class, 'traceAsString');
$a[$k] = new CutStub($a[$k]);
}
return $a;
}
private static function filterExceptionArray(string $xClass, array $a, string $xPrefix, int $filter): array
{
if (isset($a[$xPrefix.'trace'])) {
@@ -285,12 +320,10 @@ class ExceptionCaster
if (empty($a[$xPrefix.'previous'])) {
unset($a[$xPrefix.'previous']);
}
unset($a[$xPrefix.'string'], $a[Caster::PREFIX_DYNAMIC.'xdebug_message'], $a[Caster::PREFIX_DYNAMIC.'__destructorException']);
unset($a[$xPrefix.'string'], $a[Caster::PREFIX_DYNAMIC.'xdebug_message']);
if (isset($a[Caster::PREFIX_PROTECTED.'message']) && str_contains($a[Caster::PREFIX_PROTECTED.'message'], "@anonymous\0")) {
$a[Caster::PREFIX_PROTECTED.'message'] = 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];
}, $a[Caster::PREFIX_PROTECTED.'message']);
$a[Caster::PREFIX_PROTECTED.'message'] = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0], $a[Caster::PREFIX_PROTECTED.'message']);
}
if (isset($a[Caster::PREFIX_PROTECTED.'file'], $a[Caster::PREFIX_PROTECTED.'line'])) {
@@ -337,7 +370,7 @@ class ExceptionCaster
$stub->attr['file'] = $f;
$stub->attr['line'] = $caller->getStartLine();
}
} catch (\ReflectionException $e) {
} catch (\ReflectionException) {
// ignore fake class/function
}
@@ -352,9 +385,7 @@ class ExceptionCaster
$pad = null;
for ($i = $srcContext << 1; $i >= 0; --$i) {
if (isset($src[$i][$ltrim]) && "\r" !== ($c = $src[$i][$ltrim]) && "\n" !== $c) {
if (null === $pad) {
$pad = $c;
}
$pad ??= $c;
if ((' ' !== $c && "\t" !== $c) || $pad !== $c) {
break;
}

View File

@@ -0,0 +1,161 @@
<?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 FFI\CData;
use FFI\CType;
use Symfony\Component\VarDumper\Cloner\Stub;
/**
* Casts FFI extension classes to array representation.
*
* @author Nesmeyanov Kirill <nesk@xakep.ru>
*/
final class FFICaster
{
/**
* In case of "char*" contains a string, the length of which depends on
* some other parameter, then during the generation of the string it is
* possible to go beyond the allowable memory area.
*
* This restriction serves to ensure that processing does not take
* up the entire allowable PHP memory limit.
*/
private const MAX_STRING_LENGTH = 255;
public static function castCTypeOrCData(CData|CType $data, array $args, Stub $stub): array
{
if ($data instanceof CType) {
$type = $data;
$data = null;
} else {
$type = \FFI::typeof($data);
}
$stub->class = sprintf('%s<%s> size %d align %d', ($data ?? $type)::class, $type->getName(), $type->getSize(), $type->getAlignment());
return match ($type->getKind()) {
CType::TYPE_FLOAT,
CType::TYPE_DOUBLE,
\defined('\FFI\CType::TYPE_LONGDOUBLE') ? CType::TYPE_LONGDOUBLE : -1,
CType::TYPE_UINT8,
CType::TYPE_SINT8,
CType::TYPE_UINT16,
CType::TYPE_SINT16,
CType::TYPE_UINT32,
CType::TYPE_SINT32,
CType::TYPE_UINT64,
CType::TYPE_SINT64,
CType::TYPE_BOOL,
CType::TYPE_CHAR,
CType::TYPE_ENUM => null !== $data ? [Caster::PREFIX_VIRTUAL.'cdata' => $data->cdata] : [],
CType::TYPE_POINTER => self::castFFIPointer($stub, $type, $data),
CType::TYPE_STRUCT => self::castFFIStructLike($type, $data),
CType::TYPE_FUNC => self::castFFIFunction($stub, $type),
default => $args,
};
}
private static function castFFIFunction(Stub $stub, CType $type): array
{
$arguments = [];
for ($i = 0, $count = $type->getFuncParameterCount(); $i < $count; ++$i) {
$param = $type->getFuncParameterType($i);
$arguments[] = $param->getName();
}
$abi = match ($type->getFuncABI()) {
CType::ABI_DEFAULT,
CType::ABI_CDECL => '[cdecl]',
CType::ABI_FASTCALL => '[fastcall]',
CType::ABI_THISCALL => '[thiscall]',
CType::ABI_STDCALL => '[stdcall]',
CType::ABI_PASCAL => '[pascal]',
CType::ABI_REGISTER => '[register]',
CType::ABI_MS => '[ms]',
CType::ABI_SYSV => '[sysv]',
CType::ABI_VECTORCALL => '[vectorcall]',
default => '[unknown abi]'
};
$returnType = $type->getFuncReturnType();
$stub->class = $abi.' callable('.implode(', ', $arguments).'): '
.$returnType->getName();
return [Caster::PREFIX_VIRTUAL.'returnType' => $returnType];
}
private static function castFFIPointer(Stub $stub, CType $type, CData $data = null): array
{
$ptr = $type->getPointerType();
if (null === $data) {
return [Caster::PREFIX_VIRTUAL.'0' => $ptr];
}
return match ($ptr->getKind()) {
CType::TYPE_CHAR => [Caster::PREFIX_VIRTUAL.'cdata' => self::castFFIStringValue($data)],
CType::TYPE_FUNC => self::castFFIFunction($stub, $ptr),
default => [Caster::PREFIX_VIRTUAL.'cdata' => $data[0]],
};
}
private static function castFFIStringValue(CData $data): string|CutStub
{
$result = [];
for ($i = 0; $i < self::MAX_STRING_LENGTH; ++$i) {
$result[$i] = $data[$i];
if ("\0" === $result[$i]) {
return implode('', $result);
}
}
$string = implode('', $result);
$stub = new CutStub($string);
$stub->cut = -1;
$stub->value = $string;
return $stub;
}
private static function castFFIStructLike(CType $type, CData $data = null): array
{
$isUnion = ($type->getAttributes() & CType::ATTR_UNION) === CType::ATTR_UNION;
$result = [];
foreach ($type->getStructFieldNames() as $name) {
$field = $type->getStructFieldType($name);
// Retrieving the value of a field from a union containing
// a pointer is not a safe operation, because may contain
// incorrect data.
$isUnsafe = $isUnion && CType::TYPE_POINTER === $field->getKind();
if ($isUnsafe) {
$result[Caster::PREFIX_VIRTUAL.$name.'?'] = $field;
} elseif (null === $data) {
$result[Caster::PREFIX_VIRTUAL.$name] = $field;
} else {
$fieldName = $data->{$name} instanceof CData ? '' : $field->getName().' ';
$result[Caster::PREFIX_VIRTUAL.$fieldName.$name] = $data->{$name};
}
}
return $result;
}
}

View File

@@ -20,6 +20,9 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
final class FiberCaster
{
/**
* @return array
*/
public static function castFiber(\Fiber $fiber, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$prefix = Caster::PREFIX_VIRTUAL;

View File

@@ -21,6 +21,9 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class IntlCaster
{
/**
* @return array
*/
public static function castMessageFormatter(\MessageFormatter $c, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -31,6 +34,9 @@ class IntlCaster
return self::castError($c, $a);
}
/**
* @return array
*/
public static function castNumberFormatter(\NumberFormatter $c, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$a += [
@@ -108,6 +114,9 @@ class IntlCaster
return self::castError($c, $a);
}
/**
* @return array
*/
public static function castIntlTimeZone(\IntlTimeZone $c, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -125,6 +134,9 @@ class IntlCaster
return self::castError($c, $a);
}
/**
* @return array
*/
public static function castIntlCalendar(\IntlCalendar $c, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$a += [
@@ -142,6 +154,9 @@ class IntlCaster
return self::castError($c, $a);
}
/**
* @return array
*/
public static function castIntlDateFormatter(\IntlDateFormatter $c, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$a += [

View File

@@ -20,17 +20,14 @@ class LinkStub extends ConstStub
{
public $inVendor = false;
private static $vendorRoots;
private static $composerRoots;
private static array $vendorRoots;
private static array $composerRoots = [];
public function __construct(string $label, int $line = 0, string $href = null)
{
$this->value = $label;
if (null === $href) {
$href = $label;
}
if (!\is_string($href)) {
if (!\is_string($href ??= $label)) {
return;
}
if (str_starts_with($href, 'file://')) {
@@ -63,9 +60,9 @@ class LinkStub extends ConstStub
}
}
private function getComposerRoot(string $file, bool &$inVendor)
private function getComposerRoot(string $file, bool &$inVendor): string|false
{
if (null === self::$vendorRoots) {
if (!isset(self::$vendorRoots)) {
self::$vendorRoots = [];
foreach (get_declared_classes() as $class) {

View File

@@ -20,9 +20,12 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class MemcachedCaster
{
private static $optionConstants;
private static $defaultOptions;
private static array $optionConstants;
private static array $defaultOptions;
/**
* @return array
*/
public static function castMemcached(\Memcached $c, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -37,8 +40,8 @@ class MemcachedCaster
private static function getNonDefaultOptions(\Memcached $c): array
{
self::$defaultOptions = self::$defaultOptions ?? self::discoverDefaultOptions();
self::$optionConstants = self::$optionConstants ?? self::getOptionConstants();
self::$defaultOptions ??= self::discoverDefaultOptions();
self::$optionConstants ??= self::getOptionConstants();
$nonDefaultOptions = [];
foreach (self::$optionConstants as $constantKey => $value) {
@@ -56,7 +59,7 @@ class MemcachedCaster
$defaultMemcached->addServer('127.0.0.1', 11211);
$defaultOptions = [];
self::$optionConstants = self::$optionConstants ?? self::getOptionConstants();
self::$optionConstants ??= self::getOptionConstants();
foreach (self::$optionConstants as $constantKey => $value) {
$defaultOptions[$constantKey] = $defaultMemcached->getOption($value);

View File

@@ -59,6 +59,9 @@ class PdoCaster
],
];
/**
* @return array
*/
public static function castPdo(\PDO $c, array $a, Stub $stub, bool $isNested)
{
$attr = [];
@@ -76,7 +79,7 @@ class PdoCaster
if ($v && isset($v[$attr[$k]])) {
$attr[$k] = new ConstStub($v[$attr[$k]], $attr[$k]);
}
} catch (\Exception $e) {
} catch (\Exception) {
}
}
if (isset($attr[$k = 'STATEMENT_CLASS'][1])) {
@@ -108,6 +111,9 @@ class PdoCaster
return $a;
}
/**
* @return array
*/
public static function castPdoStatement(\PDOStatement $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;

View File

@@ -69,6 +69,9 @@ class PgSqlCaster
'function' => \PGSQL_DIAG_SOURCE_FUNCTION,
];
/**
* @return array
*/
public static function castLargeObject($lo, array $a, Stub $stub, bool $isNested)
{
$a['seek position'] = pg_lo_tell($lo);
@@ -76,6 +79,9 @@ class PgSqlCaster
return $a;
}
/**
* @return array
*/
public static function castLink($link, array $a, Stub $stub, bool $isNested)
{
$a['status'] = pg_connection_status($link);
@@ -108,6 +114,9 @@ class PgSqlCaster
return $a;
}
/**
* @return array
*/
public static function castResult($result, array $a, Stub $stub, bool $isNested)
{
$a['num rows'] = pg_num_rows($result);

View File

@@ -21,6 +21,9 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class ProxyManagerCaster
{
/**
* @return array
*/
public static function castProxy(ProxyInterface $c, array $a, Stub $stub, bool $isNested)
{
if ($parent = get_parent_class($c)) {

View File

@@ -31,13 +31,16 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class RdKafkaCaster
{
/**
* @return array
*/
public static function castKafkaConsumer(KafkaConsumer $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
try {
$assignment = $c->getAssignment();
} catch (RdKafkaException $e) {
} catch (RdKafkaException) {
$assignment = [];
}
@@ -51,6 +54,9 @@ class RdKafkaCaster
return $a;
}
/**
* @return array
*/
public static function castTopic(Topic $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -62,6 +68,9 @@ class RdKafkaCaster
return $a;
}
/**
* @return array
*/
public static function castTopicPartition(TopicPartition $c, array $a)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -75,6 +84,9 @@ class RdKafkaCaster
return $a;
}
/**
* @return array
*/
public static function castMessage(Message $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -86,6 +98,9 @@ class RdKafkaCaster
return $a;
}
/**
* @return array
*/
public static function castConf(Conf $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -97,6 +112,9 @@ class RdKafkaCaster
return $a;
}
/**
* @return array
*/
public static function castTopicConf(TopicConf $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -108,6 +126,9 @@ class RdKafkaCaster
return $a;
}
/**
* @return array
*/
public static function castRdKafka(\RdKafka $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -121,6 +142,9 @@ class RdKafkaCaster
return $a;
}
/**
* @return array
*/
public static function castCollectionMetadata(CollectionMetadata $c, array $a, Stub $stub, bool $isNested)
{
$a += iterator_to_array($c);
@@ -128,6 +152,9 @@ class RdKafkaCaster
return $a;
}
/**
* @return array
*/
public static function castTopicMetadata(TopicMetadata $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -140,6 +167,9 @@ class RdKafkaCaster
return $a;
}
/**
* @return array
*/
public static function castPartitionMetadata(PartitionMetadata $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -153,6 +183,9 @@ class RdKafkaCaster
return $a;
}
/**
* @return array
*/
public static function castBrokerMetadata(BrokerMetadata $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -166,13 +199,16 @@ class RdKafkaCaster
return $a;
}
private static function extractMetadata($c)
/**
* @return array
*/
private static function extractMetadata(KafkaConsumer|\RdKafka $c)
{
$prefix = Caster::PREFIX_VIRTUAL;
try {
$m = $c->getMetadata(true, null, 500);
} catch (RdKafkaException $e) {
} catch (RdKafkaException) {
return [];
}

View File

@@ -11,6 +11,7 @@
namespace Symfony\Component\VarDumper\Caster;
use Relay\Relay;
use Symfony\Component\VarDumper\Cloner\Stub;
/**
@@ -23,15 +24,15 @@ use Symfony\Component\VarDumper\Cloner\Stub;
class RedisCaster
{
private const SERIALIZERS = [
\Redis::SERIALIZER_NONE => 'NONE',
\Redis::SERIALIZER_PHP => 'PHP',
0 => 'NONE', // Redis::SERIALIZER_NONE
1 => 'PHP', // Redis::SERIALIZER_PHP
2 => 'IGBINARY', // Optional Redis::SERIALIZER_IGBINARY
];
private const MODES = [
\Redis::ATOMIC => 'ATOMIC',
\Redis::MULTI => 'MULTI',
\Redis::PIPELINE => 'PIPELINE',
0 => 'ATOMIC', // Redis::ATOMIC
1 => 'MULTI', // Redis::MULTI
2 => 'PIPELINE', // Redis::PIPELINE
];
private const COMPRESSION_MODES = [
@@ -46,7 +47,10 @@ class RedisCaster
\RedisCluster::FAILOVER_DISTRIBUTE_SLAVES => 'DISTRIBUTE_SLAVES',
];
public static function castRedis(\Redis $c, array $a, Stub $stub, bool $isNested)
/**
* @return array
*/
public static function castRedis(\Redis|Relay $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -72,6 +76,9 @@ class RedisCaster
];
}
/**
* @return array
*/
public static function castRedisArray(\RedisArray $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -84,6 +91,9 @@ class RedisCaster
];
}
/**
* @return array
*/
public static function castRedisCluster(\RedisCluster $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -102,12 +112,9 @@ class RedisCaster
return $a;
}
/**
* @param \Redis|\RedisArray|\RedisCluster $redis
*/
private static function getRedisOptions($redis, array $options = []): EnumStub
private static function getRedisOptions(\Redis|Relay|\RedisArray|\RedisCluster $redis, array $options = []): EnumStub
{
$serializer = $redis->getOption(\Redis::OPT_SERIALIZER);
$serializer = $redis->getOption(\defined('Redis::OPT_SERIALIZER') ? \Redis::OPT_SERIALIZER : 1);
if (\is_array($serializer)) {
foreach ($serializer as &$v) {
if (isset(self::SERIALIZERS[$v])) {
@@ -139,11 +146,11 @@ class RedisCaster
}
$options += [
'TCP_KEEPALIVE' => \defined('Redis::OPT_TCP_KEEPALIVE') ? $redis->getOption(\Redis::OPT_TCP_KEEPALIVE) : 0,
'READ_TIMEOUT' => $redis->getOption(\Redis::OPT_READ_TIMEOUT),
'TCP_KEEPALIVE' => \defined('Redis::OPT_TCP_KEEPALIVE') ? $redis->getOption(\Redis::OPT_TCP_KEEPALIVE) : Relay::OPT_TCP_KEEPALIVE,
'READ_TIMEOUT' => $redis->getOption(\defined('Redis::OPT_READ_TIMEOUT') ? \Redis::OPT_READ_TIMEOUT : Relay::OPT_READ_TIMEOUT),
'COMPRESSION' => $compression,
'SERIALIZER' => $serializer,
'PREFIX' => $redis->getOption(\Redis::OPT_PREFIX),
'PREFIX' => $redis->getOption(\defined('Redis::OPT_PREFIX') ? \Redis::OPT_PREFIX : Relay::OPT_PREFIX),
'SCAN' => $retry,
];

View File

@@ -35,6 +35,9 @@ class ReflectionCaster
'isVariadic' => 'isVariadic',
];
/**
* @return array
*/
public static function castClosure(\Closure $c, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -71,6 +74,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function unsetClosureFileInfo(\Closure $c, array $a)
{
unset($a[Caster::PREFIX_VIRTUAL.'file'], $a[Caster::PREFIX_VIRTUAL.'line']);
@@ -78,12 +84,12 @@ class ReflectionCaster
return $a;
}
public static function castGenerator(\Generator $c, array $a, Stub $stub, bool $isNested)
public static function castGenerator(\Generator $c, array $a, Stub $stub, bool $isNested): array
{
// Cannot create ReflectionGenerator based on a terminated Generator
try {
$reflectionGenerator = new \ReflectionGenerator($c);
} catch (\Exception $e) {
} catch (\Exception) {
$a[Caster::PREFIX_VIRTUAL.'closed'] = true;
return $a;
@@ -92,11 +98,14 @@ class ReflectionCaster
return self::castReflectionGenerator($reflectionGenerator, $a, $stub, $isNested);
}
/**
* @return array
*/
public static function castType(\ReflectionType $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
if ($c instanceof \ReflectionNamedType || \PHP_VERSION_ID < 80000) {
if ($c instanceof \ReflectionNamedType) {
$a += [
$prefix.'name' => $c instanceof \ReflectionNamedType ? $c->getName() : (string) $c,
$prefix.'allowsNull' => $c->allowsNull(),
@@ -114,6 +123,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function castAttribute(\ReflectionAttribute $c, array $a, Stub $stub, bool $isNested)
{
self::addMap($a, $c, [
@@ -124,6 +136,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function castReflectionGenerator(\ReflectionGenerator $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -144,7 +159,7 @@ class ReflectionCaster
array_unshift($trace, [
'function' => 'yield',
'file' => $function->getExecutingFile(),
'line' => $function->getExecutingLine() - (int) (\PHP_VERSION_ID < 80100),
'line' => $function->getExecutingLine(),
]);
$trace[] = $frame;
$a[$prefix.'trace'] = new TraceStub($trace, false, 0, -1, -1);
@@ -159,6 +174,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function castClass(\ReflectionClass $c, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -190,6 +208,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -197,7 +218,7 @@ class ReflectionCaster
self::addMap($a, $c, [
'returnsReference' => 'returnsReference',
'returnType' => 'getReturnType',
'class' => 'getClosureScopeClass',
'class' => \PHP_VERSION_ID >= 80111 ? 'getClosureCalledClass' : 'getClosureScopeClass',
'this' => 'getClosureThis',
]);
@@ -248,6 +269,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function castClassConstant(\ReflectionClassConstant $c, array $a, Stub $stub, bool $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'modifiers'] = implode(' ', \Reflection::getModifierNames($c->getModifiers()));
@@ -258,6 +282,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function castMethod(\ReflectionMethod $c, array $a, Stub $stub, bool $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'modifiers'] = implode(' ', \Reflection::getModifierNames($c->getModifiers()));
@@ -265,6 +292,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function castParameter(\ReflectionParameter $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -292,19 +322,22 @@ class ReflectionCaster
if ($c->isOptional()) {
try {
$a[$prefix.'default'] = $v = $c->getDefaultValue();
if ($c->isDefaultValueConstant()) {
if ($c->isDefaultValueConstant() && !\is_object($v)) {
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
}
if (null === $v) {
unset($a[$prefix.'allowsNull']);
}
} catch (\ReflectionException $e) {
} catch (\ReflectionException) {
}
}
return $a;
}
/**
* @return array
*/
public static function castProperty(\ReflectionProperty $c, array $a, Stub $stub, bool $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'modifiers'] = implode(' ', \Reflection::getModifierNames($c->getModifiers()));
@@ -315,6 +348,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function castReference(\ReflectionReference $c, array $a, Stub $stub, bool $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'id'] = $c->getId();
@@ -322,6 +358,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function castExtension(\ReflectionExtension $c, array $a, Stub $stub, bool $isNested)
{
self::addMap($a, $c, [
@@ -338,6 +377,9 @@ class ReflectionCaster
return $a;
}
/**
* @return array
*/
public static function castZendExtension(\ReflectionZendExtension $c, array $a, Stub $stub, bool $isNested)
{
self::addMap($a, $c, [
@@ -350,6 +392,9 @@ class ReflectionCaster
return $a;
}
/**
* @return string
*/
public static function getSignature(array $a)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -402,7 +447,7 @@ class ReflectionCaster
return $signature;
}
private static function addExtra(array &$a, \Reflector $c)
private static function addExtra(array &$a, \Reflector $c): void
{
$x = isset($a[Caster::PREFIX_VIRTUAL.'extra']) ? $a[Caster::PREFIX_VIRTUAL.'extra']->value : [];
@@ -418,10 +463,10 @@ class ReflectionCaster
}
}
private static function addMap(array &$a, object $c, array $map, string $prefix = Caster::PREFIX_VIRTUAL)
private static function addMap(array &$a, object $c, array $map, string $prefix = Caster::PREFIX_VIRTUAL): void
{
foreach ($map as $k => $m) {
if (\PHP_VERSION_ID >= 80000 && 'isDisabled' === $k) {
if ('isDisabled' === $k) {
continue;
}
@@ -433,10 +478,8 @@ class ReflectionCaster
private static function addAttributes(array &$a, \Reflector $c, string $prefix = Caster::PREFIX_VIRTUAL): void
{
if (\PHP_VERSION_ID >= 80000) {
foreach ($c->getAttributes() as $n) {
$a[$prefix.'attributes'][] = $n;
}
foreach ($c->getAttributes() as $n) {
$a[$prefix.'attributes'][] = $n;
}
}
}

View File

@@ -22,14 +22,14 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class ResourceCaster
{
/**
* @param \CurlHandle|resource $h
*/
public static function castCurl($h, array $a, Stub $stub, bool $isNested): array
public static function castCurl(\CurlHandle $h, array $a, Stub $stub, bool $isNested): array
{
return curl_getinfo($h);
}
/**
* @return array
*/
public static function castDba($dba, array $a, Stub $stub, bool $isNested)
{
$list = dba_list();
@@ -38,12 +38,15 @@ class ResourceCaster
return $a;
}
/**
* @return array
*/
public static function castProcess($process, array $a, Stub $stub, bool $isNested)
{
return proc_get_status($process);
}
public static function castStream($stream, array $a, Stub $stub, bool $isNested)
public static function castStream($stream, array $a, Stub $stub, bool $isNested): array
{
$a = stream_get_meta_data($stream) + static::castStreamContext($stream, $a, $stub, $isNested);
if ($a['uri'] ?? false) {
@@ -53,11 +56,17 @@ class ResourceCaster
return $a;
}
/**
* @return array
*/
public static function castStreamContext($stream, array $a, Stub $stub, bool $isNested)
{
return @stream_context_get_params($stream) ?: $a;
}
/**
* @return array
*/
public static function castGd($gd, array $a, Stub $stub, bool $isNested)
{
$a['size'] = imagesx($gd).'x'.imagesy($gd);
@@ -66,15 +75,9 @@ class ResourceCaster
return $a;
}
public static function castMysqlLink($h, array $a, Stub $stub, bool $isNested)
{
$a['host'] = mysql_get_host_info($h);
$a['protocol'] = mysql_get_proto_info($h);
$a['server'] = mysql_get_server_info($h);
return $a;
}
/**
* @return array
*/
public static function castOpensslX509($h, array $a, Stub $stub, bool $isNested)
{
$stub->cut = -1;
@@ -89,7 +92,7 @@ class ResourceCaster
$a += [
'subject' => new EnumStub(array_intersect_key($info['subject'], ['organizationName' => true, 'commonName' => true])),
'issuer' => new EnumStub(array_intersect_key($info['issuer'], ['organizationName' => true, 'commonName' => true])),
'expiry' => new ConstStub(date(\DateTime::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
'expiry' => new ConstStub(date(\DateTimeInterface::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
'fingerprint' => new EnumStub([
'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)),
'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)),

View File

@@ -0,0 +1,27 @@
<?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 any arbitrary value.
*
* @author Alexandre Daubois <alex.daubois@gmail.com>
*/
class ScalarStub extends Stub
{
public function __construct(mixed $value)
{
$this->value = $value;
}
}

View File

@@ -29,16 +29,25 @@ class SplCaster
\SplFileObject::READ_CSV => 'READ_CSV',
];
/**
* @return array
*/
public static function castArrayObject(\ArrayObject $c, array $a, Stub $stub, bool $isNested)
{
return self::castSplArray($c, $a, $stub, $isNested);
}
/**
* @return array
*/
public static function castArrayIterator(\ArrayIterator $c, array $a, Stub $stub, bool $isNested)
{
return self::castSplArray($c, $a, $stub, $isNested);
}
/**
* @return array
*/
public static function castHeap(\Iterator $c, array $a, Stub $stub, bool $isNested)
{
$a += [
@@ -48,6 +57,9 @@ class SplCaster
return $a;
}
/**
* @return array
*/
public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, Stub $stub, bool $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
@@ -63,6 +75,9 @@ class SplCaster
return $a;
}
/**
* @return array
*/
public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, bool $isNested)
{
static $map = [
@@ -94,38 +109,30 @@ class SplCaster
unset($a["\0SplFileInfo\0fileName"]);
unset($a["\0SplFileInfo\0pathName"]);
if (\PHP_VERSION_ID < 80000) {
if (false === $c->getPathname()) {
$a[$prefix.'⚠'] = 'The parent constructor was not called: the object is in an invalid state';
return $a;
try {
$c->isReadable();
} catch (\RuntimeException $e) {
if ('Object not initialized' !== $e->getMessage()) {
throw $e;
}
} else {
try {
$c->isReadable();
} catch (\RuntimeException $e) {
if ('Object not initialized' !== $e->getMessage()) {
throw $e;
}
$a[$prefix.'⚠'] = 'The parent constructor was not called: the object is in an invalid state';
$a[$prefix.'⚠'] = 'The parent constructor was not called: the object is in an invalid state';
return $a;
} catch (\Error $e) {
if ('Object not initialized' !== $e->getMessage()) {
throw $e;
}
$a[$prefix.'⚠'] = 'The parent constructor was not called: the object is in an invalid state';
return $a;
return $a;
} catch (\Error $e) {
if ('Object not initialized' !== $e->getMessage()) {
throw $e;
}
$a[$prefix.'⚠'] = 'The parent constructor was not called: the object is in an invalid state';
return $a;
}
foreach ($map as $key => $accessor) {
try {
$a[$prefix.$key] = $c->$accessor();
} catch (\Exception $e) {
} catch (\Exception) {
}
}
@@ -147,6 +154,9 @@ class SplCaster
return $a;
}
/**
* @return array
*/
public static function castFileObject(\SplFileObject $c, array $a, Stub $stub, bool $isNested)
{
static $map = [
@@ -163,7 +173,7 @@ class SplCaster
foreach ($map as $key => $accessor) {
try {
$a[$prefix.$key] = $c->$accessor();
} catch (\Exception $e) {
} catch (\Exception) {
}
}
@@ -184,6 +194,9 @@ class SplCaster
return $a;
}
/**
* @return array
*/
public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $stub, bool $isNested)
{
$storage = [];
@@ -192,10 +205,10 @@ class SplCaster
$clone = clone $c;
foreach ($clone as $obj) {
$storage[] = [
$storage[] = new EnumStub([
'object' => $obj,
'info' => $clone->getInfo(),
];
]);
}
$a += [
@@ -205,6 +218,9 @@ class SplCaster
return $a;
}
/**
* @return array
*/
public static function castOuterIterator(\OuterIterator $c, array $a, Stub $stub, bool $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'innerIterator'] = $c->getInnerIterator();
@@ -212,6 +228,9 @@ class SplCaster
return $a;
}
/**
* @return array
*/
public static function castWeakReference(\WeakReference $c, array $a, Stub $stub, bool $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'object'] = $c->get();
@@ -219,20 +238,42 @@ class SplCaster
return $a;
}
private static function castSplArray($c, array $a, Stub $stub, bool $isNested): array
/**
* @return array
*/
public static function castWeakMap(\WeakMap $c, array $a, Stub $stub, bool $isNested)
{
$map = [];
foreach (clone $c as $obj => $data) {
$map[] = new EnumStub([
'object' => $obj,
'data' => $data,
]);
}
$a += [
Caster::PREFIX_VIRTUAL.'map' => $map,
];
return $a;
}
private static function castSplArray(\ArrayObject|\ArrayIterator $c, array $a, Stub $stub, bool $isNested): array
{
$prefix = Caster::PREFIX_VIRTUAL;
$flags = $c->getFlags();
if (!($flags & \ArrayObject::STD_PROP_LIST)) {
$c->setFlags(\ArrayObject::STD_PROP_LIST);
$a = Caster::castObject($c, \get_class($c), method_exists($c, '__debugInfo'), $stub->class);
$a = Caster::castObject($c, $c::class, method_exists($c, '__debugInfo'), $stub->class);
$c->setFlags($flags);
}
if (\PHP_VERSION_ID < 70400) {
$a[$prefix.'storage'] = $c->getArrayCopy();
}
unset($a["\0ArrayObject\0storage"], $a["\0ArrayIterator\0storage"]);
$a += [
$prefix.'storage' => $c->getArrayCopy(),
$prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST),
$prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS),
];

View File

@@ -22,6 +22,9 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class StubCaster
{
/**
* @return array
*/
public static function castStub(Stub $c, array $a, Stub $stub, bool $isNested)
{
if ($isNested) {
@@ -43,11 +46,17 @@ class StubCaster
return $a;
}
/**
* @return array
*/
public static function castCutArray(CutArrayStub $c, array $a, Stub $stub, bool $isNested)
{
return $isNested ? $c->preservedSubset : $a;
}
/**
* @return array
*/
public static function cutInternals($obj, array $a, Stub $stub, bool $isNested)
{
if ($isNested) {
@@ -59,6 +68,9 @@ class StubCaster
return $a;
}
/**
* @return array
*/
public static function castEnum(EnumStub $c, array $a, Stub $stub, bool $isNested)
{
if ($isNested) {
@@ -81,4 +93,15 @@ class StubCaster
return $a;
}
/**
* @return array
*/
public static function castScalar(ScalarStub $scalarStub, array $a, Stub $stub)
{
$stub->type = Stub::TYPE_SCALAR;
$stub->attr['value'] = $scalarStub->value;
return $a;
}
}

View File

@@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\VarDumper\Cloner\Stub;
use Symfony\Component\VarExporter\Internal\LazyObjectState;
/**
* @final
@@ -30,6 +31,9 @@ class SymfonyCaster
'format' => 'getRequestFormat',
];
/**
* @return array
*/
public static function castRequest(Request $request, array $a, Stub $stub, bool $isNested)
{
$clone = null;
@@ -37,9 +41,7 @@ class SymfonyCaster
foreach (self::REQUEST_GETTERS as $prop => $getter) {
$key = Caster::PREFIX_PROTECTED.$prop;
if (\array_key_exists($key, $a) && null === $a[$key]) {
if (null === $clone) {
$clone = clone $request;
}
$clone ??= clone $request;
$a[Caster::PREFIX_VIRTUAL.$prop] = $clone->{$getter}();
}
}
@@ -47,9 +49,12 @@ class SymfonyCaster
return $a;
}
/**
* @return array
*/
public static function castHttpClient($client, array $a, Stub $stub, bool $isNested)
{
$multiKey = sprintf("\0%s\0multi", \get_class($client));
$multiKey = sprintf("\0%s\0multi", $client::class);
if (isset($a[$multiKey])) {
$a[$multiKey] = new CutStub($a[$multiKey]);
}
@@ -57,6 +62,9 @@ class SymfonyCaster
return $a;
}
/**
* @return array
*/
public static function castHttpClientResponse($response, array $a, Stub $stub, bool $isNested)
{
$stub->cut += \count($a);
@@ -69,6 +77,37 @@ class SymfonyCaster
return $a;
}
/**
* @return array
*/
public static function castLazyObjectState($state, array $a, Stub $stub, bool $isNested)
{
if (!$isNested) {
return $a;
}
$stub->cut += \count($a) - 1;
$instance = $a['realInstance'] ?? null;
$a = ['status' => new ConstStub(match ($a['status']) {
LazyObjectState::STATUS_INITIALIZED_FULL => 'INITIALIZED_FULL',
LazyObjectState::STATUS_INITIALIZED_PARTIAL => 'INITIALIZED_PARTIAL',
LazyObjectState::STATUS_UNINITIALIZED_FULL => 'UNINITIALIZED_FULL',
LazyObjectState::STATUS_UNINITIALIZED_PARTIAL => 'UNINITIALIZED_PARTIAL',
}, $a['status'])];
if ($instance) {
$a['realInstance'] = $instance;
--$stub->cut;
}
return $a;
}
/**
* @return array
*/
public static function castUuid(Uuid $uuid, array $a, Stub $stub, bool $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'toBase58'] = $uuid->toBase58();
@@ -82,6 +121,9 @@ class SymfonyCaster
return $a;
}
/**
* @return array
*/
public static function castUlid(Ulid $ulid, array $a, Stub $stub, bool $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'toBase58'] = $ulid->toBase58();

View File

@@ -0,0 +1,25 @@
<?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;
/**
* Represents an uninitialized property.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class UninitializedStub extends ConstStub
{
public function __construct(\ReflectionProperty $property)
{
parent::__construct('?'.($property->hasType() ? ' '.$property->getType() : ''), 'Uninitialized property');
}
}

View File

@@ -43,6 +43,9 @@ class XmlReaderCaster
\XMLReader::XML_DECLARATION => 'XML_DECLARATION',
];
/**
* @return array
*/
public static function castXmlReader(\XMLReader $reader, array $a, Stub $stub, bool $isNested)
{
try {
@@ -52,7 +55,7 @@ class XmlReaderCaster
'VALIDATE' => @$reader->getParserProperty(\XMLReader::VALIDATE),
'SUBST_ENTITIES' => @$reader->getParserProperty(\XMLReader::SUBST_ENTITIES),
];
} catch (\Error $e) {
} catch (\Error) {
$properties = [
'LOADDTD' => false,
'DEFAULTATTRS' => false,
@@ -82,6 +85,7 @@ class XmlReaderCaster
$info[$props]->cut = $count;
}
$a = Caster::filter($a, Caster::EXCLUDE_UNINITIALIZED, [], $count);
$info = Caster::filter($info, Caster::EXCLUDE_EMPTY, [], $count);
// +2 because hasValue and hasAttributes are always filtered
$stub->cut += $count + 2;

View File

@@ -47,6 +47,9 @@ class XmlResourceCaster
\XML_ERROR_EXTERNAL_ENTITY_HANDLING => 'XML_ERROR_EXTERNAL_ENTITY_HANDLING',
];
/**
* @return array
*/
public static function castXml($h, array $a, Stub $stub, bool $isNested)
{
$a['current_byte_index'] = xml_get_current_byte_index($h);