updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -17,40 +17,42 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts Amqp related classes to array representation.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @final since Symfony 4.4
*/
class AmqpCaster
{
private static $flags = array(
AMQP_DURABLE => 'AMQP_DURABLE',
AMQP_PASSIVE => 'AMQP_PASSIVE',
AMQP_EXCLUSIVE => 'AMQP_EXCLUSIVE',
AMQP_AUTODELETE => 'AMQP_AUTODELETE',
AMQP_INTERNAL => 'AMQP_INTERNAL',
AMQP_NOLOCAL => 'AMQP_NOLOCAL',
AMQP_AUTOACK => 'AMQP_AUTOACK',
AMQP_IFEMPTY => 'AMQP_IFEMPTY',
AMQP_IFUNUSED => 'AMQP_IFUNUSED',
AMQP_MANDATORY => 'AMQP_MANDATORY',
AMQP_IMMEDIATE => 'AMQP_IMMEDIATE',
AMQP_MULTIPLE => 'AMQP_MULTIPLE',
AMQP_NOWAIT => 'AMQP_NOWAIT',
AMQP_REQUEUE => 'AMQP_REQUEUE',
);
private const FLAGS = [
\AMQP_DURABLE => 'AMQP_DURABLE',
\AMQP_PASSIVE => 'AMQP_PASSIVE',
\AMQP_EXCLUSIVE => 'AMQP_EXCLUSIVE',
\AMQP_AUTODELETE => 'AMQP_AUTODELETE',
\AMQP_INTERNAL => 'AMQP_INTERNAL',
\AMQP_NOLOCAL => 'AMQP_NOLOCAL',
\AMQP_AUTOACK => 'AMQP_AUTOACK',
\AMQP_IFEMPTY => 'AMQP_IFEMPTY',
\AMQP_IFUNUSED => 'AMQP_IFUNUSED',
\AMQP_MANDATORY => 'AMQP_MANDATORY',
\AMQP_IMMEDIATE => 'AMQP_IMMEDIATE',
\AMQP_MULTIPLE => 'AMQP_MULTIPLE',
\AMQP_NOWAIT => 'AMQP_NOWAIT',
\AMQP_REQUEUE => 'AMQP_REQUEUE',
];
private static $exchangeTypes = array(
AMQP_EX_TYPE_DIRECT => 'AMQP_EX_TYPE_DIRECT',
AMQP_EX_TYPE_FANOUT => 'AMQP_EX_TYPE_FANOUT',
AMQP_EX_TYPE_TOPIC => 'AMQP_EX_TYPE_TOPIC',
AMQP_EX_TYPE_HEADERS => 'AMQP_EX_TYPE_HEADERS',
);
private const EXCHANGE_TYPES = [
\AMQP_EX_TYPE_DIRECT => 'AMQP_EX_TYPE_DIRECT',
\AMQP_EX_TYPE_FANOUT => 'AMQP_EX_TYPE_FANOUT',
\AMQP_EX_TYPE_TOPIC => 'AMQP_EX_TYPE_TOPIC',
\AMQP_EX_TYPE_HEADERS => 'AMQP_EX_TYPE_HEADERS',
];
public static function castConnection(\AMQPConnection $c, array $a, Stub $stub, $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
$a += array(
$a += [
$prefix.'is_connected' => $c->isConnected(),
);
];
// Recent version of the extension already expose private properties
if (isset($a["\x00AMQPConnection\x00login"])) {
@@ -64,7 +66,7 @@ class AmqpCaster
$timeout = $c->getTimeout();
}
$a += array(
$a += [
$prefix.'is_connected' => $c->isConnected(),
$prefix.'login' => $c->getLogin(),
$prefix.'password' => $c->getPassword(),
@@ -72,7 +74,7 @@ class AmqpCaster
$prefix.'vhost' => $c->getVhost(),
$prefix.'port' => $c->getPort(),
$prefix.'read_timeout' => $timeout,
);
];
return $a;
}
@@ -81,21 +83,21 @@ class AmqpCaster
{
$prefix = Caster::PREFIX_VIRTUAL;
$a += array(
$a += [
$prefix.'is_connected' => $c->isConnected(),
$prefix.'channel_id' => $c->getChannelId(),
);
];
// Recent version of the extension already expose private properties
if (isset($a["\x00AMQPChannel\x00connection"])) {
return $a;
}
$a += array(
$a += [
$prefix.'connection' => $c->getConnection(),
$prefix.'prefetch_size' => $c->getPrefetchSize(),
$prefix.'prefetch_count' => $c->getPrefetchCount(),
);
];
return $a;
}
@@ -104,21 +106,21 @@ class AmqpCaster
{
$prefix = Caster::PREFIX_VIRTUAL;
$a += array(
$a += [
$prefix.'flags' => self::extractFlags($c->getFlags()),
);
];
// Recent version of the extension already expose private properties
if (isset($a["\x00AMQPQueue\x00name"])) {
return $a;
}
$a += array(
$a += [
$prefix.'connection' => $c->getConnection(),
$prefix.'channel' => $c->getChannel(),
$prefix.'name' => $c->getName(),
$prefix.'arguments' => $c->getArguments(),
);
];
return $a;
}
@@ -127,11 +129,11 @@ class AmqpCaster
{
$prefix = Caster::PREFIX_VIRTUAL;
$a += array(
$a += [
$prefix.'flags' => self::extractFlags($c->getFlags()),
);
];
$type = isset(self::$exchangeTypes[$c->getType()]) ? new ConstStub(self::$exchangeTypes[$c->getType()], $c->getType()) : $c->getType();
$type = isset(self::EXCHANGE_TYPES[$c->getType()]) ? new ConstStub(self::EXCHANGE_TYPES[$c->getType()], $c->getType()) : $c->getType();
// Recent version of the extension already expose private properties
if (isset($a["\x00AMQPExchange\x00name"])) {
@@ -140,13 +142,13 @@ class AmqpCaster
return $a;
}
$a += array(
$a += [
$prefix.'connection' => $c->getConnection(),
$prefix.'channel' => $c->getChannel(),
$prefix.'name' => $c->getName(),
$prefix.'type' => $type,
$prefix.'arguments' => $c->getArguments(),
);
];
return $a;
}
@@ -165,10 +167,10 @@ class AmqpCaster
}
if (!($filter & Caster::EXCLUDE_VERBOSE)) {
$a += array($prefix.'body' => $c->getBody());
$a += [$prefix.'body' => $c->getBody()];
}
$a += array(
$a += [
$prefix.'delivery_tag' => $c->getDeliveryTag(),
$prefix.'is_redelivery' => $c->isRedelivery(),
$prefix.'exchange_name' => $c->getExchangeName(),
@@ -186,23 +188,23 @@ class AmqpCaster
$prefix.'type' => $c->getType(),
$prefix.'user_id' => $c->getUserId(),
$prefix.'app_id' => $c->getAppId(),
);
];
return $a;
}
private static function extractFlags($flags)
private static function extractFlags(int $flags): ConstStub
{
$flagsArray = array();
$flagsArray = [];
foreach (self::$flags as $value => $name) {
foreach (self::FLAGS as $value => $name) {
if ($flags & $value) {
$flagsArray[] = $name;
}
}
if (!$flagsArray) {
$flagsArray = array('AMQP_NOPARAM');
$flagsArray = ['AMQP_NOPARAM'];
}
return new ConstStub(implode('|', $flagsArray), $flags);

View File

@@ -20,15 +20,15 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class ArgsStub extends EnumStub
{
private static $parameters = array();
private static $parameters = [];
public function __construct(array $args, string $function, ?string $class)
{
list($variadic, $params) = self::getParameters($function, $class);
[$variadic, $params] = self::getParameters($function, $class);
$values = array();
$values = [];
foreach ($args as $k => $v) {
$values[$k] = !is_scalar($v) && !$v instanceof Stub ? new CutStub($v) : $v;
$values[$k] = !\is_scalar($v) && !$v instanceof Stub ? new CutStub($v) : $v;
}
if (null === $params) {
parent::__construct($values, false);
@@ -41,7 +41,7 @@ class ArgsStub extends EnumStub
$values[] = new EnumStub(array_splice($values, \count($params)), false);
$params[] = $variadic;
}
if (array('...') === $params) {
if (['...'] === $params) {
$this->dumpKeys = false;
$this->value = $values[0]->value;
} else {
@@ -49,7 +49,7 @@ class ArgsStub extends EnumStub
}
}
private static function getParameters($function, $class)
private static function getParameters(string $function, ?string $class): array
{
if (isset(self::$parameters[$k = $class.'::'.$function])) {
return self::$parameters[$k];
@@ -58,11 +58,11 @@ class ArgsStub extends EnumStub
try {
$r = null !== $class ? new \ReflectionMethod($class, $function) : new \ReflectionFunction($function);
} catch (\ReflectionException $e) {
return array(null, null);
return [null, null];
}
$variadic = '...';
$params = array();
$params = [];
foreach ($r->getParameters() as $v) {
$k = '$'.$v->name;
if ($v->isPassedByReference()) {
@@ -75,6 +75,6 @@ class ArgsStub extends EnumStub
}
}
return self::$parameters[$k] = array($variadic, $params);
return self::$parameters[$k] = [$variadic, $params];
}
}

View File

@@ -22,60 +22,64 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*/
class Caster
{
const EXCLUDE_VERBOSE = 1;
const EXCLUDE_VIRTUAL = 2;
const EXCLUDE_DYNAMIC = 4;
const EXCLUDE_PUBLIC = 8;
const EXCLUDE_PROTECTED = 16;
const EXCLUDE_PRIVATE = 32;
const EXCLUDE_NULL = 64;
const EXCLUDE_EMPTY = 128;
const EXCLUDE_NOT_IMPORTANT = 256;
const EXCLUDE_STRICT = 512;
public const EXCLUDE_VERBOSE = 1;
public const EXCLUDE_VIRTUAL = 2;
public const EXCLUDE_DYNAMIC = 4;
public const EXCLUDE_PUBLIC = 8;
public const EXCLUDE_PROTECTED = 16;
public const EXCLUDE_PRIVATE = 32;
public const EXCLUDE_NULL = 64;
public const EXCLUDE_EMPTY = 128;
public const EXCLUDE_NOT_IMPORTANT = 256;
public const EXCLUDE_STRICT = 512;
const PREFIX_VIRTUAL = "\0~\0";
const PREFIX_DYNAMIC = "\0+\0";
const PREFIX_PROTECTED = "\0*\0";
public const PREFIX_VIRTUAL = "\0~\0";
public const PREFIX_DYNAMIC = "\0+\0";
public const PREFIX_PROTECTED = "\0*\0";
/**
* Casts objects to arrays and adds the dynamic property prefix.
*
* @param object $obj The object to cast
* @param string $class The class of the object
* @param bool $hasDebugInfo Whether the __debugInfo method exists on $obj or not
*
* @return array The array-cast of the object, with prefixed dynamic properties
*/
public static function castObject($obj, $class, $hasDebugInfo = false)
public static function castObject($obj, string $class, bool $hasDebugInfo = false, string $debugClass = null): array
{
if ($hasDebugInfo) {
$a = $obj->__debugInfo();
} elseif ($obj instanceof \Closure) {
$a = array();
} else {
$a = (array) $obj;
try {
$debugInfo = $obj->__debugInfo();
} catch (\Exception $e) {
// ignore failing __debugInfo()
$hasDebugInfo = false;
}
}
$a = $obj instanceof \Closure ? [] : (array) $obj;
if ($obj instanceof \__PHP_Incomplete_Class) {
return $a;
}
if ($a) {
static $publicProperties = array();
static $publicProperties = [];
$debugClass = $debugClass ?? get_debug_type($obj);
$i = 0;
$prefixedKeys = array();
$prefixedKeys = [];
foreach ($a as $k => $v) {
if (isset($k[0]) ? "\0" !== $k[0] : \PHP_VERSION_ID >= 70200) {
if (!isset($publicProperties[$class])) {
foreach (get_class_vars($class) as $prop => $v) {
$publicProperties[$class][$prop] = true;
foreach ((new \ReflectionClass($class))->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
$publicProperties[$class][$prop->name] = true;
}
}
if (!isset($publicProperties[$class][$k])) {
$prefixedKeys[$i] = self::PREFIX_DYNAMIC.$k;
}
} elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) {
$prefixedKeys[$i] = "\0".get_parent_class($class).'@anonymous'.strrchr($k, "\0");
} elseif ($debugClass !== $class && 1 === strpos($k, $class)) {
$prefixedKeys[$i] = "\0".$debugClass.strrchr($k, "\0");
}
++$i;
}
@@ -88,6 +92,20 @@ class Caster
}
}
if ($hasDebugInfo && \is_array($debugInfo)) {
foreach ($debugInfo as $k => $v) {
if (!isset($k[0]) || "\0" !== $k[0]) {
if (\array_key_exists(self::PREFIX_DYNAMIC.$k, $a)) {
continue;
}
$k = self::PREFIX_VIRTUAL.$k;
}
unset($a[$k]);
$a[$k] = $v;
}
}
return $a;
}
@@ -104,7 +122,7 @@ class Caster
*
* @return array The filtered array
*/
public static function filter(array $a, $filter, array $listedProperties = array(), &$count = 0)
public static function filter(array $a, int $filter, array $listedProperties = [], ?int &$count = 0): array
{
$count = 0;
@@ -114,7 +132,7 @@ class Caster
if (null === $v) {
$type |= self::EXCLUDE_NULL & $filter;
$type |= self::EXCLUDE_EMPTY & $filter;
} elseif (false === $v || '' === $v || '0' === $v || 0 === $v || 0.0 === $v || array() === $v) {
} elseif (false === $v || '' === $v || '0' === $v || 0 === $v || 0.0 === $v || [] === $v) {
$type |= self::EXCLUDE_EMPTY & $filter;
}
if ((self::EXCLUDE_NOT_IMPORTANT & $filter) && !\in_array($k, $listedProperties, true)) {
@@ -145,7 +163,7 @@ class Caster
return $a;
}
public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, $isNested)
public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, bool $isNested): array
{
if (isset($a['__PHP_Incomplete_Class_Name'])) {
$stub->class .= '('.$a['__PHP_Incomplete_Class_Name'].')';

View File

@@ -33,16 +33,16 @@ class ClassStub extends ConstStub
if ($callable instanceof \Closure) {
$r = new \ReflectionFunction($callable);
} elseif (\is_object($callable)) {
$r = array($callable, '__invoke');
$r = [$callable, '__invoke'];
} elseif (\is_array($callable)) {
$r = $callable;
} elseif (false !== $i = strpos($callable, '::')) {
$r = array(substr($callable, 0, $i), substr($callable, 2 + $i));
$r = [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));
$r = [substr($identifier, 0, $i), substr($identifier, 2 + $i)];
} else {
$r = new \ReflectionClass($identifier);
}
@@ -55,17 +55,17 @@ class ClassStub extends ConstStub
}
}
if (false !== strpos($identifier, "class@anonymous\0")) {
$this->value = $identifier = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) {
return \class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[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, array(), new Stub(), true);
$s = ReflectionCaster::castFunctionAbstract($r, [], new Stub(), true, Caster::EXCLUDE_VERBOSE);
$s = ReflectionCaster::getSignature($s);
if ('()' === substr($identifier, -2)) {
if (str_ends_with($identifier, '()')) {
$this->value = substr_replace($identifier, $s, -2);
} else {
$this->value .= $s;

View File

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

View File

@@ -28,6 +28,11 @@ class CutStub extends Stub
case 'object':
$this->type = self::TYPE_OBJECT;
$this->class = \get_class($value);
if ($value instanceof \Closure) {
ReflectionCaster::castClosure($value, [], $this, true, Caster::EXCLUDE_VERBOSE);
}
$this->cut = -1;
break;

View File

@@ -17,55 +17,57 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts DOM related classes to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class DOMCaster
{
private static $errorCodes = array(
DOM_PHP_ERR => 'DOM_PHP_ERR',
DOM_INDEX_SIZE_ERR => 'DOM_INDEX_SIZE_ERR',
DOMSTRING_SIZE_ERR => 'DOMSTRING_SIZE_ERR',
DOM_HIERARCHY_REQUEST_ERR => 'DOM_HIERARCHY_REQUEST_ERR',
DOM_WRONG_DOCUMENT_ERR => 'DOM_WRONG_DOCUMENT_ERR',
DOM_INVALID_CHARACTER_ERR => 'DOM_INVALID_CHARACTER_ERR',
DOM_NO_DATA_ALLOWED_ERR => 'DOM_NO_DATA_ALLOWED_ERR',
DOM_NO_MODIFICATION_ALLOWED_ERR => 'DOM_NO_MODIFICATION_ALLOWED_ERR',
DOM_NOT_FOUND_ERR => 'DOM_NOT_FOUND_ERR',
DOM_NOT_SUPPORTED_ERR => 'DOM_NOT_SUPPORTED_ERR',
DOM_INUSE_ATTRIBUTE_ERR => 'DOM_INUSE_ATTRIBUTE_ERR',
DOM_INVALID_STATE_ERR => 'DOM_INVALID_STATE_ERR',
DOM_SYNTAX_ERR => 'DOM_SYNTAX_ERR',
DOM_INVALID_MODIFICATION_ERR => 'DOM_INVALID_MODIFICATION_ERR',
DOM_NAMESPACE_ERR => 'DOM_NAMESPACE_ERR',
DOM_INVALID_ACCESS_ERR => 'DOM_INVALID_ACCESS_ERR',
DOM_VALIDATION_ERR => 'DOM_VALIDATION_ERR',
);
private const ERROR_CODES = [
\DOM_PHP_ERR => 'DOM_PHP_ERR',
\DOM_INDEX_SIZE_ERR => 'DOM_INDEX_SIZE_ERR',
\DOMSTRING_SIZE_ERR => 'DOMSTRING_SIZE_ERR',
\DOM_HIERARCHY_REQUEST_ERR => 'DOM_HIERARCHY_REQUEST_ERR',
\DOM_WRONG_DOCUMENT_ERR => 'DOM_WRONG_DOCUMENT_ERR',
\DOM_INVALID_CHARACTER_ERR => 'DOM_INVALID_CHARACTER_ERR',
\DOM_NO_DATA_ALLOWED_ERR => 'DOM_NO_DATA_ALLOWED_ERR',
\DOM_NO_MODIFICATION_ALLOWED_ERR => 'DOM_NO_MODIFICATION_ALLOWED_ERR',
\DOM_NOT_FOUND_ERR => 'DOM_NOT_FOUND_ERR',
\DOM_NOT_SUPPORTED_ERR => 'DOM_NOT_SUPPORTED_ERR',
\DOM_INUSE_ATTRIBUTE_ERR => 'DOM_INUSE_ATTRIBUTE_ERR',
\DOM_INVALID_STATE_ERR => 'DOM_INVALID_STATE_ERR',
\DOM_SYNTAX_ERR => 'DOM_SYNTAX_ERR',
\DOM_INVALID_MODIFICATION_ERR => 'DOM_INVALID_MODIFICATION_ERR',
\DOM_NAMESPACE_ERR => 'DOM_NAMESPACE_ERR',
\DOM_INVALID_ACCESS_ERR => 'DOM_INVALID_ACCESS_ERR',
\DOM_VALIDATION_ERR => 'DOM_VALIDATION_ERR',
];
private static $nodeTypes = array(
XML_ELEMENT_NODE => 'XML_ELEMENT_NODE',
XML_ATTRIBUTE_NODE => 'XML_ATTRIBUTE_NODE',
XML_TEXT_NODE => 'XML_TEXT_NODE',
XML_CDATA_SECTION_NODE => 'XML_CDATA_SECTION_NODE',
XML_ENTITY_REF_NODE => 'XML_ENTITY_REF_NODE',
XML_ENTITY_NODE => 'XML_ENTITY_NODE',
XML_PI_NODE => 'XML_PI_NODE',
XML_COMMENT_NODE => 'XML_COMMENT_NODE',
XML_DOCUMENT_NODE => 'XML_DOCUMENT_NODE',
XML_DOCUMENT_TYPE_NODE => 'XML_DOCUMENT_TYPE_NODE',
XML_DOCUMENT_FRAG_NODE => 'XML_DOCUMENT_FRAG_NODE',
XML_NOTATION_NODE => 'XML_NOTATION_NODE',
XML_HTML_DOCUMENT_NODE => 'XML_HTML_DOCUMENT_NODE',
XML_DTD_NODE => 'XML_DTD_NODE',
XML_ELEMENT_DECL_NODE => 'XML_ELEMENT_DECL_NODE',
XML_ATTRIBUTE_DECL_NODE => 'XML_ATTRIBUTE_DECL_NODE',
XML_ENTITY_DECL_NODE => 'XML_ENTITY_DECL_NODE',
XML_NAMESPACE_DECL_NODE => 'XML_NAMESPACE_DECL_NODE',
);
private const NODE_TYPES = [
\XML_ELEMENT_NODE => 'XML_ELEMENT_NODE',
\XML_ATTRIBUTE_NODE => 'XML_ATTRIBUTE_NODE',
\XML_TEXT_NODE => 'XML_TEXT_NODE',
\XML_CDATA_SECTION_NODE => 'XML_CDATA_SECTION_NODE',
\XML_ENTITY_REF_NODE => 'XML_ENTITY_REF_NODE',
\XML_ENTITY_NODE => 'XML_ENTITY_NODE',
\XML_PI_NODE => 'XML_PI_NODE',
\XML_COMMENT_NODE => 'XML_COMMENT_NODE',
\XML_DOCUMENT_NODE => 'XML_DOCUMENT_NODE',
\XML_DOCUMENT_TYPE_NODE => 'XML_DOCUMENT_TYPE_NODE',
\XML_DOCUMENT_FRAG_NODE => 'XML_DOCUMENT_FRAG_NODE',
\XML_NOTATION_NODE => 'XML_NOTATION_NODE',
\XML_HTML_DOCUMENT_NODE => 'XML_HTML_DOCUMENT_NODE',
\XML_DTD_NODE => 'XML_DTD_NODE',
\XML_ELEMENT_DECL_NODE => 'XML_ELEMENT_DECL_NODE',
\XML_ATTRIBUTE_DECL_NODE => 'XML_ATTRIBUTE_DECL_NODE',
\XML_ENTITY_DECL_NODE => 'XML_ENTITY_DECL_NODE',
\XML_NAMESPACE_DECL_NODE => 'XML_NAMESPACE_DECL_NODE',
];
public static function castException(\DOMException $e, array $a, Stub $stub, $isNested)
{
$k = Caster::PREFIX_PROTECTED.'code';
if (isset($a[$k], self::$errorCodes[$a[$k]])) {
$a[$k] = new ConstStub(self::$errorCodes[$a[$k]], $a[$k]);
if (isset($a[$k], self::ERROR_CODES[$a[$k]])) {
$a[$k] = new ConstStub(self::ERROR_CODES[$a[$k]], $a[$k]);
}
return $a;
@@ -73,29 +75,29 @@ class DOMCaster
public static function castLength($dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'length' => $dom->length,
);
];
return $a;
}
public static function castImplementation($dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'Core' => '1.0',
Caster::PREFIX_VIRTUAL.'XML' => '2.0',
);
];
return $a;
}
public static function castNode(\DOMNode $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'nodeName' => $dom->nodeName,
'nodeValue' => new CutStub($dom->nodeValue),
'nodeType' => new ConstStub(self::$nodeTypes[$dom->nodeType], $dom->nodeType),
'nodeType' => new ConstStub(self::NODE_TYPES[$dom->nodeType], $dom->nodeType),
'parentNode' => new CutStub($dom->parentNode),
'childNodes' => $dom->childNodes,
'firstChild' => new CutStub($dom->firstChild),
@@ -109,30 +111,30 @@ class DOMCaster
'localName' => $dom->localName,
'baseURI' => $dom->baseURI ? new LinkStub($dom->baseURI) : $dom->baseURI,
'textContent' => new CutStub($dom->textContent),
);
];
return $a;
}
public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'nodeName' => $dom->nodeName,
'nodeValue' => new CutStub($dom->nodeValue),
'nodeType' => new ConstStub(self::$nodeTypes[$dom->nodeType], $dom->nodeType),
'nodeType' => new ConstStub(self::NODE_TYPES[$dom->nodeType], $dom->nodeType),
'prefix' => $dom->prefix,
'localName' => $dom->localName,
'namespaceURI' => $dom->namespaceURI,
'ownerDocument' => new CutStub($dom->ownerDocument),
'parentNode' => new CutStub($dom->parentNode),
);
];
return $a;
}
public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, $isNested, $filter = 0)
{
$a += array(
$a += [
'doctype' => $dom->doctype,
'implementation' => $dom->implementation,
'documentElement' => new CutStub($dom->documentElement),
@@ -152,12 +154,12 @@ class DOMCaster
'preserveWhiteSpace' => $dom->preserveWhiteSpace,
'recover' => $dom->recover,
'substituteEntities' => $dom->substituteEntities,
);
];
if (!($filter & Caster::EXCLUDE_VERBOSE)) {
$formatOutput = $dom->formatOutput;
$dom->formatOutput = true;
$a += array(Caster::PREFIX_VIRTUAL.'xml' => $dom->saveXML());
$a += [Caster::PREFIX_VIRTUAL.'xml' => $dom->saveXML()];
$dom->formatOutput = $formatOutput;
}
@@ -166,136 +168,136 @@ class DOMCaster
public static function castCharacterData(\DOMCharacterData $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'data' => $dom->data,
'length' => $dom->length,
);
];
return $a;
}
public static function castAttr(\DOMAttr $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'name' => $dom->name,
'specified' => $dom->specified,
'value' => $dom->value,
'ownerElement' => $dom->ownerElement,
'schemaTypeInfo' => $dom->schemaTypeInfo,
);
];
return $a;
}
public static function castElement(\DOMElement $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'tagName' => $dom->tagName,
'schemaTypeInfo' => $dom->schemaTypeInfo,
);
];
return $a;
}
public static function castText(\DOMText $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'wholeText' => $dom->wholeText,
);
];
return $a;
}
public static function castTypeinfo(\DOMTypeinfo $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'typeName' => $dom->typeName,
'typeNamespace' => $dom->typeNamespace,
);
];
return $a;
}
public static function castDomError(\DOMDomError $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$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, $isNested)
{
$a += array(
$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;
}
public static function castDocumentType(\DOMDocumentType $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'name' => $dom->name,
'entities' => $dom->entities,
'notations' => $dom->notations,
'publicId' => $dom->publicId,
'systemId' => $dom->systemId,
'internalSubset' => $dom->internalSubset,
);
];
return $a;
}
public static function castNotation(\DOMNotation $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'publicId' => $dom->publicId,
'systemId' => $dom->systemId,
);
];
return $a;
}
public static function castEntity(\DOMEntity $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'publicId' => $dom->publicId,
'systemId' => $dom->systemId,
'notationName' => $dom->notationName,
'actualEncoding' => $dom->actualEncoding,
'encoding' => $dom->encoding,
'version' => $dom->version,
);
];
return $a;
}
public static function castProcessingInstruction(\DOMProcessingInstruction $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'target' => $dom->target,
'data' => $dom->data,
);
];
return $a;
}
public static function castXPath(\DOMXPath $dom, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
'document' => $dom->document,
);
];
return $a;
}

View File

@@ -17,6 +17,8 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts DateTimeInterface related classes to array representation.
*
* @author Dany Maillard <danymaillard93b@gmail.com>
*
* @final since Symfony 4.4
*/
class DateCaster
{
@@ -33,7 +35,11 @@ class DateCaster
.($location ? ($d->format('I') ? "\nDST On" : "\nDST Off") : '')
;
$a = array();
unset(
$a[Caster::PREFIX_DYNAMIC.'date'],
$a[Caster::PREFIX_DYNAMIC.'timezone'],
$a[Caster::PREFIX_DYNAMIC.'timezone_type']
);
$a[$prefix.'date'] = new ConstStub(self::formatDateTime($d, $location ? ' e (P)' : ' P'), $title);
$stub->class .= $d->format(' @U');
@@ -43,21 +49,22 @@ class DateCaster
public static function castInterval(\DateInterval $interval, array $a, Stub $stub, $isNested, $filter)
{
$now = new \DateTimeImmutable();
$now = new \DateTimeImmutable('@0', new \DateTimeZone('UTC'));
$numberOfSeconds = $now->add($interval)->getTimestamp() - $now->getTimestamp();
$title = number_format($numberOfSeconds, 0, '.', ' ').'s';
$i = array(Caster::PREFIX_VIRTUAL.'interval' => new ConstStub(self::formatInterval($interval), $title));
$i = [Caster::PREFIX_VIRTUAL.'interval' => new ConstStub(self::formatInterval($interval), $title)];
return $filter & Caster::EXCLUDE_VERBOSE ? $i : $i + $a;
}
private static function formatInterval(\DateInterval $i)
private static function formatInterval(\DateInterval $i): string
{
$format = '%R ';
if (0 === $i->y && 0 === $i->m && ($i->h >= 24 || $i->i >= 60 || $i->s >= 60)) {
$i = date_diff($d = new \DateTime(), date_add(clone $d, $i)); // recalculate carry over points
$d = new \DateTimeImmutable('@0', new \DateTimeZone('UTC'));
$i = $d->diff($d->add($i)); // recalculate carry over points
$format .= 0 < $i->days ? '%ad ' : '';
} else {
$format .= ($i->y ? '%yy ' : '').($i->m ? '%mm ' : '').($i->d ? '%dd ' : '');
@@ -75,20 +82,20 @@ class DateCaster
$formatted = (new \DateTime('now', $timeZone))->format($location ? 'e (P)' : 'P');
$title = $location && \extension_loaded('intl') ? \Locale::getDisplayRegion('-'.$location['country_code']) : '';
$z = array(Caster::PREFIX_VIRTUAL.'timezone' => new ConstStub($formatted, $title));
$z = [Caster::PREFIX_VIRTUAL.'timezone' => new ConstStub($formatted, $title)];
return $filter & Caster::EXCLUDE_VERBOSE ? $z : $z + $a;
}
public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, $isNested, $filter)
{
$dates = array();
if (\PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/bug.php?id=74639
$dates = [];
if (\PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/74639
foreach (clone $p as $i => $d) {
if (self::PERIOD_LIMIT === $i) {
$now = new \DateTimeImmutable();
$now = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
$dates[] = sprintf('%s more', ($end = $p->getEndDate())
? ceil(($end->format('U.u') - $d->format('U.u')) / ($now->add($p->getDateInterval())->format('U.u') - $now->format('U.u')))
? ceil(($end->format('U.u') - $d->format('U.u')) / ((int) $now->add($p->getDateInterval())->format('U.u') - (int) $now->format('U.u')))
: $p->recurrences - $i
);
break;
@@ -98,24 +105,24 @@ class DateCaster
}
$period = sprintf(
'every %s, from %s (%s) %s',
'every %s, from %s%s %s',
self::formatInterval($p->getDateInterval()),
$p->include_start_date ? '[' : ']',
self::formatDateTime($p->getStartDate()),
$p->include_start_date ? 'included' : 'excluded',
($end = $p->getEndDate()) ? 'to '.self::formatDateTime($end) : 'recurring '.$p->recurrences.' time/s'
($end = $p->getEndDate()) ? 'to '.self::formatDateTime($end).(\PHP_VERSION_ID >= 80200 && $p->include_end_date ? ']' : '[') : 'recurring '.$p->recurrences.' time/s'
);
$p = array(Caster::PREFIX_VIRTUAL.'period' => new ConstStub($period, implode("\n", $dates)));
$p = [Caster::PREFIX_VIRTUAL.'period' => new ConstStub($period, implode("\n", $dates))];
return $filter & Caster::EXCLUDE_VERBOSE ? $p : $p + $a;
}
private static function formatDateTime(\DateTimeInterface $d, $extra = '')
private static function formatDateTime(\DateTimeInterface $d, string $extra = ''): string
{
return $d->format('Y-m-d H:i:'.self::formatSeconds($d->format('s'), $d->format('u')).$extra);
}
private static function formatSeconds($s, $us)
private static function formatSeconds(string $s, string $us): string
{
return sprintf('%02d.%s', $s, 0 === ($len = \strlen($t = rtrim($us, '0'))) ? '0' : ($len <= 3 ? str_pad($t, 3, '0') : $us));
}

View File

@@ -20,13 +20,15 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts Doctrine related classes to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class DoctrineCaster
{
public static function castCommonProxy(CommonProxy $proxy, array $a, Stub $stub, $isNested)
{
foreach (array('__cloner__', '__initializer__') as $k) {
if (array_key_exists($k, $a)) {
foreach (['__cloner__', '__initializer__'] as $k) {
if (\array_key_exists($k, $a)) {
unset($a[$k]);
++$stub->cut;
}
@@ -37,8 +39,8 @@ class DoctrineCaster
public static function castOrmProxy(OrmProxy $proxy, array $a, Stub $stub, $isNested)
{
foreach (array('_entityPersister', '_identifier') as $k) {
if (array_key_exists($k = "\0Doctrine\\ORM\\Proxy\\Proxy\0".$k, $a)) {
foreach (['_entityPersister', '_identifier'] as $k) {
if (\array_key_exists($k = "\0Doctrine\\ORM\\Proxy\\Proxy\0".$k, $a)) {
unset($a[$k]);
++$stub->cut;
}
@@ -49,8 +51,8 @@ class DoctrineCaster
public static function castPersistentCollection(PersistentCollection $coll, array $a, Stub $stub, $isNested)
{
foreach (array('snapshot', 'association', 'typeClass') as $k) {
if (array_key_exists($k = "\0Doctrine\\ORM\\PersistentCollection\0".$k, $a)) {
foreach (['snapshot', 'association', 'typeClass'] as $k) {
if (\array_key_exists($k = "\0Doctrine\\ORM\\PersistentCollection\0".$k, $a)) {
$a[$k] = new CutStub($a[$k]);
}
}

View File

@@ -0,0 +1,70 @@
<?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 Ds\Collection;
use Ds\Map;
use Ds\Pair;
use Symfony\Component\VarDumper\Cloner\Stub;
/**
* Casts Ds extension classes to array representation.
*
* @author Jáchym Toušek <enumag@gmail.com>
*
* @final since Symfony 4.4
*/
class DsCaster
{
public static function castCollection(Collection $c, array $a, Stub $stub, bool $isNested): array
{
$a[Caster::PREFIX_VIRTUAL.'count'] = $c->count();
$a[Caster::PREFIX_VIRTUAL.'capacity'] = $c->capacity();
if (!$c instanceof Map) {
$a += $c->toArray();
}
return $a;
}
public static function castMap(Map $c, array $a, Stub $stub, bool $isNested): array
{
foreach ($c as $k => $v) {
$a[] = new DsPairStub($k, $v);
}
return $a;
}
public static function castPair(Pair $c, array $a, Stub $stub, bool $isNested): array
{
foreach ($c->toArray() as $k => $v) {
$a[Caster::PREFIX_VIRTUAL.$k] = $v;
}
return $a;
}
public static function castPairStub(DsPairStub $c, array $a, Stub $stub, bool $isNested): array
{
if ($isNested) {
$stub->class = Pair::class;
$stub->value = null;
$stub->handle = 0;
$a = $c->value;
}
return $a;
}
}

View File

@@ -0,0 +1,28 @@
<?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;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class DsPairStub extends Stub
{
public function __construct($key, $value)
{
$this->value = [
Caster::PREFIX_VIRTUAL.'key' => $key,
Caster::PREFIX_VIRTUAL.'value' => $value,
];
}
}

View File

@@ -11,7 +11,7 @@
namespace Symfony\Component\VarDumper\Caster;
use Symfony\Component\Debug\Exception\SilencedErrorContext;
use Symfony\Component\ErrorHandler\Exception\SilencedErrorContext;
use Symfony\Component\VarDumper\Cloner\Stub;
use Symfony\Component\VarDumper\Exception\ThrowingCasterException;
@@ -19,30 +19,32 @@ use Symfony\Component\VarDumper\Exception\ThrowingCasterException;
* Casts common Exception classes to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class ExceptionCaster
{
public static $srcContext = 1;
public static $traceArgs = true;
public static $errorTypes = array(
E_DEPRECATED => 'E_DEPRECATED',
E_USER_DEPRECATED => 'E_USER_DEPRECATED',
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
E_ERROR => 'E_ERROR',
E_WARNING => 'E_WARNING',
E_PARSE => 'E_PARSE',
E_NOTICE => 'E_NOTICE',
E_CORE_ERROR => 'E_CORE_ERROR',
E_CORE_WARNING => 'E_CORE_WARNING',
E_COMPILE_ERROR => 'E_COMPILE_ERROR',
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
E_USER_ERROR => 'E_USER_ERROR',
E_USER_WARNING => 'E_USER_WARNING',
E_USER_NOTICE => 'E_USER_NOTICE',
E_STRICT => 'E_STRICT',
);
public static $errorTypes = [
\E_DEPRECATED => 'E_DEPRECATED',
\E_USER_DEPRECATED => 'E_USER_DEPRECATED',
\E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
\E_ERROR => 'E_ERROR',
\E_WARNING => 'E_WARNING',
\E_PARSE => 'E_PARSE',
\E_NOTICE => 'E_NOTICE',
\E_CORE_ERROR => 'E_CORE_ERROR',
\E_CORE_WARNING => 'E_CORE_WARNING',
\E_COMPILE_ERROR => 'E_COMPILE_ERROR',
\E_COMPILE_WARNING => 'E_COMPILE_WARNING',
\E_USER_ERROR => 'E_USER_ERROR',
\E_USER_WARNING => 'E_USER_WARNING',
\E_USER_NOTICE => 'E_USER_NOTICE',
\E_STRICT => 'E_STRICT',
];
private static $framesCache = array();
private static $framesCache = [];
public static function castError(\Error $e, array $a, Stub $stub, $isNested, $filter = 0)
{
@@ -71,8 +73,7 @@ class ExceptionCaster
if (isset($a[$xPrefix.'previous'], $a[$trace]) && $a[$xPrefix.'previous'] instanceof \Exception) {
$b = (array) $a[$xPrefix.'previous'];
$class = \get_class($a[$xPrefix.'previous']);
$class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
$class = get_debug_type($a[$xPrefix.'previous']);
self::traceUnshift($b[$xPrefix.'trace'], $class, $b[$prefix.'file'], $b[$prefix.'line']);
$a[$trace] = new TraceStub($b[$xPrefix.'trace'], false, 0, -\count($a[$trace]->value));
}
@@ -94,10 +95,10 @@ class ExceptionCaster
$a[$s] = new ConstStub(self::$errorTypes[$a[$s]], $a[$s]);
}
$trace = array(array(
$trace = [[
'file' => $a[$sPrefix.'file'],
'line' => $a[$sPrefix.'line'],
));
]];
if (isset($a[$sPrefix.'trace'])) {
$trace = array_merge($trace, $a[$sPrefix.'trace']);
@@ -119,16 +120,16 @@ class ExceptionCaster
$frames = $trace->value;
$prefix = Caster::PREFIX_VIRTUAL;
$a = array();
$a = [];
$j = \count($frames);
if (0 > $i = $trace->sliceOffset) {
$i = max(0, $j + $i);
}
if (!isset($trace->value[$i])) {
return array();
return [];
}
$lastCall = isset($frames[$i]['function']) ? (isset($frames[$i]['class']) ? $frames[0]['class'].$frames[$i]['type'] : '').$frames[$i]['function'].'()' : '';
$frames[] = array('function' => '');
$frames[] = ['function' => ''];
$collapse = false;
for ($j += $trace->numberingOffset - $i++; isset($frames[$i]); ++$i, --$j) {
@@ -136,19 +137,19 @@ class ExceptionCaster
$call = isset($f['function']) ? (isset($f['class']) ? $f['class'].$f['type'] : '').$f['function'] : '???';
$frame = new FrameStub(
array(
'object' => isset($f['object']) ? $f['object'] : null,
'class' => isset($f['class']) ? $f['class'] : null,
'type' => isset($f['type']) ? $f['type'] : null,
'function' => isset($f['function']) ? $f['function'] : null,
) + $frames[$i - 1],
[
'object' => $f['object'] ?? null,
'class' => $f['class'] ?? null,
'type' => $f['type'] ?? null,
'function' => $f['function'] ?? null,
] + $frames[$i - 1],
false,
true
);
$f = self::castFrameStub($frame, array(), $frame, true);
$f = self::castFrameStub($frame, [], $frame, true);
if (isset($f[$prefix.'src'])) {
foreach ($f[$prefix.'src']->value as $label => $frame) {
if (0 === strpos($label, "\0~collapse=0")) {
if (str_starts_with($label, "\0~collapse=0")) {
if ($collapse) {
$label = substr_replace($label, '1', 11, 1);
} else {
@@ -159,7 +160,7 @@ class ExceptionCaster
}
$f = $frames[$i - 1];
if ($trace->keepArgs && !empty($f['args']) && $frame instanceof EnumStub) {
$frame->value['arguments'] = new ArgsStub($f['args'], isset($f['function']) ? $f['function'] : null, isset($f['class']) ? $f['class'] : null);
$frame->value['arguments'] = new ArgsStub($f['args'], $f['function'] ?? null, $f['class'] ?? null);
}
} elseif ('???' !== $lastCall) {
$label = new ClassStub($lastCall);
@@ -204,44 +205,49 @@ class ExceptionCaster
$f['file'] = substr($f['file'], 0, -\strlen($match[0]));
$f['line'] = (int) $match[1];
}
$caller = isset($f['function']) ? sprintf('in %s() on line %d', (isset($f['class']) ? $f['class'].$f['type'] : '').$f['function'], $f['line']) : null;
$src = $f['line'];
$srcKey = $f['file'];
$ellipsis = new LinkStub($srcKey, 0);
$srcAttr = 'collapse='.(int) $ellipsis->inVendor;
$ellipsisTail = isset($ellipsis->attr['ellipsis-tail']) ? $ellipsis->attr['ellipsis-tail'] : 0;
$ellipsis = isset($ellipsis->attr['ellipsis']) ? $ellipsis->attr['ellipsis'] : 0;
$ellipsisTail = $ellipsis->attr['ellipsis-tail'] ?? 0;
$ellipsis = $ellipsis->attr['ellipsis'] ?? 0;
if (file_exists($f['file']) && 0 <= self::$srcContext) {
if (!empty($f['class']) && (is_subclass_of($f['class'], 'Twig\Template') || is_subclass_of($f['class'], 'Twig_Template')) && method_exists($f['class'], 'getDebugInfo')) {
$template = isset($f['object']) ? $f['object'] : unserialize(sprintf('O:%d:"%s":0:{}', \strlen($f['class']), $f['class']));
$ellipsis = 0;
$templateSrc = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : '');
$templateInfo = $template->getDebugInfo();
if (isset($templateInfo[$f['line']])) {
if (!method_exists($template, 'getSourceContext') || !file_exists($templatePath = $template->getSourceContext()->getPath())) {
$templatePath = null;
}
if ($templateSrc) {
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, $caller, 'twig', $templatePath);
$srcKey = ($templatePath ?: $template->getTemplateName()).':'.$templateInfo[$f['line']];
$template = null;
if (isset($f['object'])) {
$template = $f['object'];
} elseif ((new \ReflectionClass($f['class']))->isInstantiable()) {
$template = unserialize(sprintf('O:%d:"%s":0:{}', \strlen($f['class']), $f['class']));
}
if (null !== $template) {
$ellipsis = 0;
$templateSrc = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : '');
$templateInfo = $template->getDebugInfo();
if (isset($templateInfo[$f['line']])) {
if (!method_exists($template, 'getSourceContext') || !file_exists($templatePath = $template->getSourceContext()->getPath())) {
$templatePath = null;
}
if ($templateSrc) {
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, 'twig', $templatePath, $f);
$srcKey = ($templatePath ?: $template->getTemplateName()).':'.$templateInfo[$f['line']];
}
}
}
}
if ($srcKey == $f['file']) {
$src = self::extractSource(file_get_contents($f['file']), $f['line'], self::$srcContext, $caller, 'php', $f['file']);
$src = self::extractSource(file_get_contents($f['file']), $f['line'], self::$srcContext, 'php', $f['file'], $f);
$srcKey .= ':'.$f['line'];
if ($ellipsis) {
$ellipsis += 1 + \strlen($f['line']);
}
}
$srcAttr .= '&separator= ';
$srcAttr .= sprintf('&separator= &file=%s&line=%d', rawurlencode($f['file']), $f['line']);
} else {
$srcAttr .= '&separator=:';
}
$srcAttr .= $ellipsis ? '&ellipsis-type=path&ellipsis='.$ellipsis.'&ellipsis-tail='.$ellipsisTail : '';
self::$framesCache[$cacheKey] = $a[$prefix.'src'] = new EnumStub(array("\0~$srcAttr\0$srcKey" => $src));
self::$framesCache[$cacheKey] = $a[$prefix.'src'] = new EnumStub(["\0~$srcAttr\0$srcKey" => $src]);
}
}
@@ -261,13 +267,13 @@ class ExceptionCaster
return $a;
}
private static function filterExceptionArray($xClass, array $a, $xPrefix, $filter)
private static function filterExceptionArray(string $xClass, array $a, string $xPrefix, int $filter): array
{
if (isset($a[$xPrefix.'trace'])) {
$trace = $a[$xPrefix.'trace'];
unset($a[$xPrefix.'trace']); // Ensures the trace is always last
} else {
$trace = array();
$trace = [];
}
if (!($filter & Caster::EXCLUDE_VERBOSE) && $trace) {
@@ -281,9 +287,9 @@ class ExceptionCaster
}
unset($a[$xPrefix.'string'], $a[Caster::PREFIX_DYNAMIC.'xdebug_message'], $a[Caster::PREFIX_DYNAMIC.'__destructorException']);
if (isset($a[Caster::PREFIX_PROTECTED.'message']) && false !== strpos($a[Caster::PREFIX_PROTECTED.'message'], "class@anonymous\0")) {
$a[Caster::PREFIX_PROTECTED.'message'] = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) {
return \class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
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']);
}
@@ -294,28 +300,53 @@ class ExceptionCaster
return $a;
}
private static function traceUnshift(&$trace, $class, $file, $line)
private static function traceUnshift(array &$trace, ?string $class, string $file, int $line): void
{
if (isset($trace[0]['file'], $trace[0]['line']) && $trace[0]['file'] === $file && $trace[0]['line'] === $line) {
return;
}
array_unshift($trace, array(
array_unshift($trace, [
'function' => $class ? 'new '.$class : null,
'file' => $file,
'line' => $line,
));
]);
}
private static function extractSource($srcLines, $line, $srcContext, $title, $lang, $file = null)
private static function extractSource(string $srcLines, int $line, int $srcContext, string $lang, ?string $file, array $frame): EnumStub
{
$srcLines = explode("\n", $srcLines);
$src = array();
$src = [];
for ($i = $line - 1 - $srcContext; $i <= $line - 1 + $srcContext; ++$i) {
$src[] = (isset($srcLines[$i]) ? $srcLines[$i] : '')."\n";
$src[] = ($srcLines[$i] ?? '')."\n";
}
if ($frame['function'] ?? false) {
$stub = new CutStub(new \stdClass());
$stub->class = (isset($frame['class']) ? $frame['class'].$frame['type'] : '').$frame['function'];
$stub->type = Stub::TYPE_OBJECT;
$stub->attr['cut_hash'] = true;
$stub->attr['file'] = $frame['file'];
$stub->attr['line'] = $frame['line'];
try {
$caller = isset($frame['class']) ? new \ReflectionMethod($frame['class'], $frame['function']) : new \ReflectionFunction($frame['function']);
$stub->class .= ReflectionCaster::getSignature(ReflectionCaster::castFunctionAbstract($caller, [], $stub, true, Caster::EXCLUDE_VERBOSE));
if ($f = $caller->getFileName()) {
$stub->attr['file'] = $f;
$stub->attr['line'] = $caller->getStartLine();
}
} catch (\ReflectionException $e) {
// ignore fake class/function
}
$srcLines = ["\0~separator=\0" => $stub];
} else {
$stub = null;
$srcLines = [];
}
$srcLines = array();
$ltrim = 0;
do {
$pad = null;
@@ -342,7 +373,7 @@ class ExceptionCaster
if ($i !== $srcContext) {
$c = new ConstStub('default', $c);
} else {
$c = new ConstStub($c, $title);
$c = new ConstStub($c, $stub ? 'in '.$stub->class : '');
if (null !== $file) {
$c->attr['file'] = $file;
$c->attr['line'] = $line;

View File

@@ -18,6 +18,8 @@ use Symfony\Component\VarDumper\Cloner\Stub;
*
* @author Hamza Amrouche <hamza.simperfit@gmail.com>
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class GmpCaster
{

View File

@@ -0,0 +1,37 @@
<?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 Imagine\Image\ImageInterface;
use Symfony\Component\VarDumper\Cloner\Stub;
/**
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
final class ImagineCaster
{
public static function castImage(ImageInterface $c, array $a, Stub $stub, bool $isNested): array
{
$imgData = $c->get('png');
if (\strlen($imgData) > 1 * 1000 * 1000) {
$a += [
Caster::PREFIX_VIRTUAL.'image' => new ConstStub($c->getSize()),
];
} else {
$a += [
Caster::PREFIX_VIRTUAL.'image' => new ImgStub($imgData, 'image/png', $c->getSize()),
];
}
return $a;
}
}

View File

@@ -0,0 +1,26 @@
<?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;
/**
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
class ImgStub extends ConstStub
{
public function __construct(string $data, string $contentType, string $size)
{
$this->value = '';
$this->attr['img-data'] = $data;
$this->attr['img-size'] = $size;
$this->attr['content-type'] = $contentType;
}
}

View File

@@ -16,25 +16,27 @@ use Symfony\Component\VarDumper\Cloner\Stub;
/**
* @author Nicolas Grekas <p@tchwork.com>
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
*
* @final since Symfony 4.4
*/
class IntlCaster
{
public static function castMessageFormatter(\MessageFormatter $c, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'locale' => $c->getLocale(),
Caster::PREFIX_VIRTUAL.'pattern' => $c->getPattern(),
);
];
return self::castError($c, $a);
}
public static function castNumberFormatter(\NumberFormatter $c, array $a, Stub $stub, $isNested, $filter = 0)
{
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'locale' => $c->getLocale(),
Caster::PREFIX_VIRTUAL.'pattern' => $c->getPattern(),
);
];
if ($filter & Caster::EXCLUDE_VERBOSE) {
$stub->cut += 3;
@@ -42,9 +44,9 @@ class IntlCaster
return self::castError($c, $a);
}
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'attributes' => new EnumStub(
array(
[
'PARSE_INT_ONLY' => $c->getAttribute(\NumberFormatter::PARSE_INT_ONLY),
'GROUPING_USED' => $c->getAttribute(\NumberFormatter::GROUPING_USED),
'DECIMAL_ALWAYS_SHOWN' => $c->getAttribute(\NumberFormatter::DECIMAL_ALWAYS_SHOWN),
@@ -65,10 +67,10 @@ class IntlCaster
'MIN_SIGNIFICANT_DIGITS' => $c->getAttribute(\NumberFormatter::MIN_SIGNIFICANT_DIGITS),
'MAX_SIGNIFICANT_DIGITS' => $c->getAttribute(\NumberFormatter::MAX_SIGNIFICANT_DIGITS),
'LENIENT_PARSE' => $c->getAttribute(\NumberFormatter::LENIENT_PARSE),
)
]
),
Caster::PREFIX_VIRTUAL.'text_attributes' => new EnumStub(
array(
[
'POSITIVE_PREFIX' => $c->getTextAttribute(\NumberFormatter::POSITIVE_PREFIX),
'POSITIVE_SUFFIX' => $c->getTextAttribute(\NumberFormatter::POSITIVE_SUFFIX),
'NEGATIVE_PREFIX' => $c->getTextAttribute(\NumberFormatter::NEGATIVE_PREFIX),
@@ -77,10 +79,10 @@ class IntlCaster
'CURRENCY_CODE' => $c->getTextAttribute(\NumberFormatter::CURRENCY_CODE),
'DEFAULT_RULESET' => $c->getTextAttribute(\NumberFormatter::DEFAULT_RULESET),
'PUBLIC_RULESETS' => $c->getTextAttribute(\NumberFormatter::PUBLIC_RULESETS),
)
]
),
Caster::PREFIX_VIRTUAL.'symbols' => new EnumStub(
array(
[
'DECIMAL_SEPARATOR_SYMBOL' => $c->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL),
'GROUPING_SEPARATOR_SYMBOL' => $c->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL),
'PATTERN_SEPARATOR_SYMBOL' => $c->getSymbol(\NumberFormatter::PATTERN_SEPARATOR_SYMBOL),
@@ -99,25 +101,25 @@ class IntlCaster
'NAN_SYMBOL' => $c->getSymbol(\NumberFormatter::NAN_SYMBOL),
'SIGNIFICANT_DIGIT_SYMBOL' => $c->getSymbol(\NumberFormatter::SIGNIFICANT_DIGIT_SYMBOL),
'MONETARY_GROUPING_SEPARATOR_SYMBOL' => $c->getSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL),
)
),
);
]
),
];
return self::castError($c, $a);
}
public static function castIntlTimeZone(\IntlTimeZone $c, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'display_name' => $c->getDisplayName(),
Caster::PREFIX_VIRTUAL.'id' => $c->getID(),
Caster::PREFIX_VIRTUAL.'raw_offset' => $c->getRawOffset(),
);
];
if ($c->useDaylightTime()) {
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'dst_savings' => $c->getDSTSavings(),
);
];
}
return self::castError($c, $a);
@@ -125,25 +127,24 @@ class IntlCaster
public static function castIntlCalendar(\IntlCalendar $c, array $a, Stub $stub, $isNested, $filter = 0)
{
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'type' => $c->getType(),
Caster::PREFIX_VIRTUAL.'first_day_of_week' => $c->getFirstDayOfWeek(),
Caster::PREFIX_VIRTUAL.'minimal_days_in_first_week' => $c->getMinimalDaysInFirstWeek(),
Caster::PREFIX_VIRTUAL.'repeated_wall_time_option' => $c->getRepeatedWallTimeOption(),
Caster::PREFIX_VIRTUAL.'skipped_wall_time_option' => $c->getSkippedWallTimeOption(),
Caster::PREFIX_VIRTUAL.'time' => $c->getTime(),
Caster::PREFIX_VIRTUAL.'type' => $c->getType(),
Caster::PREFIX_VIRTUAL.'in_daylight_time' => $c->inDaylightTime(),
Caster::PREFIX_VIRTUAL.'is_lenient' => $c->isLenient(),
Caster::PREFIX_VIRTUAL.'time_zone' => ($filter & Caster::EXCLUDE_VERBOSE) ? new CutStub($c->getTimeZone()) : $c->getTimeZone(),
);
];
return self::castError($c, $a);
}
public static function castIntlDateFormatter(\IntlDateFormatter $c, array $a, Stub $stub, $isNested, $filter = 0)
{
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'locale' => $c->getLocale(),
Caster::PREFIX_VIRTUAL.'pattern' => $c->getPattern(),
Caster::PREFIX_VIRTUAL.'calendar' => $c->getCalendar(),
@@ -152,7 +153,7 @@ class IntlCaster
Caster::PREFIX_VIRTUAL.'date_type' => $c->getDateType(),
Caster::PREFIX_VIRTUAL.'calendar_object' => ($filter & Caster::EXCLUDE_VERBOSE) ? new CutStub($c->getCalendarObject()) : $c->getCalendarObject(),
Caster::PREFIX_VIRTUAL.'time_zone' => ($filter & Caster::EXCLUDE_VERBOSE) ? new CutStub($c->getTimeZone()) : $c->getTimeZone(),
);
];
return self::castError($c, $a);
}
@@ -160,10 +161,10 @@ class IntlCaster
private static function castError($c, array $a): array
{
if ($errorCode = $c->getErrorCode()) {
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'error_code' => $errorCode,
Caster::PREFIX_VIRTUAL.'error_message' => $c->getErrorMessage(),
);
];
}
return $a;

View File

@@ -23,7 +23,7 @@ class LinkStub extends ConstStub
private static $vendorRoots;
private static $composerRoots;
public function __construct($label, int $line = 0, $href = null)
public function __construct(string $label, int $line = 0, string $href = null)
{
$this->value = $label;
@@ -33,12 +33,12 @@ class LinkStub extends ConstStub
if (!\is_string($href)) {
return;
}
if (0 === strpos($href, 'file://')) {
if (str_starts_with($href, 'file://')) {
if ($href === $label) {
$label = substr($label, 7);
}
$href = substr($href, 7);
} elseif (false !== strpos($href, '://')) {
} elseif (str_contains($href, '://')) {
$this->attr['href'] = $href;
return;
@@ -63,15 +63,15 @@ class LinkStub extends ConstStub
}
}
private function getComposerRoot($file, &$inVendor)
private function getComposerRoot(string $file, bool &$inVendor)
{
if (null === self::$vendorRoots) {
self::$vendorRoots = array();
self::$vendorRoots = [];
foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$v = \dirname(\dirname($r->getFileName()));
$v = \dirname($r->getFileName(), 2);
if (file_exists($v.'/composer/installed.json')) {
self::$vendorRoots[] = $v.\DIRECTORY_SEPARATOR;
}
@@ -85,7 +85,7 @@ class LinkStub extends ConstStub
}
foreach (self::$vendorRoots as $root) {
if ($inVendor = 0 === strpos($file, $root)) {
if ($inVendor = str_starts_with($file, $root)) {
return $root;
}
}

View File

@@ -15,6 +15,8 @@ use Symfony\Component\VarDumper\Cloner\Stub;
/**
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
*
* @final since Symfony 4.4
*/
class MemcachedCaster
{
@@ -23,22 +25,22 @@ class MemcachedCaster
public static function castMemcached(\Memcached $c, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'servers' => $c->getServerList(),
Caster::PREFIX_VIRTUAL.'options' => new EnumStub(
self::getNonDefaultOptions($c)
),
);
];
return $a;
}
private static function getNonDefaultOptions(\Memcached $c)
private static function getNonDefaultOptions(\Memcached $c): array
{
self::$defaultOptions = self::$defaultOptions ?? self::discoverDefaultOptions();
self::$optionConstants = self::$optionConstants ?? self::getOptionConstants();
$nonDefaultOptions = array();
$nonDefaultOptions = [];
foreach (self::$optionConstants as $constantKey => $value) {
if (self::$defaultOptions[$constantKey] !== $option = $c->getOption($value)) {
$nonDefaultOptions[$constantKey] = $option;
@@ -48,12 +50,12 @@ class MemcachedCaster
return $nonDefaultOptions;
}
private static function discoverDefaultOptions()
private static function discoverDefaultOptions(): array
{
$defaultMemcached = new \Memcached();
$defaultMemcached->addServer('127.0.0.1', 11211);
$defaultOptions = array();
$defaultOptions = [];
self::$optionConstants = self::$optionConstants ?? self::getOptionConstants();
foreach (self::$optionConstants as $constantKey => $value) {
@@ -63,13 +65,13 @@ class MemcachedCaster
return $defaultOptions;
}
private static function getOptionConstants()
private static function getOptionConstants(): array
{
$reflectedMemcached = new \ReflectionClass(\Memcached::class);
$optionConstants = array();
$optionConstants = [];
foreach ($reflectedMemcached->getConstants() as $constantKey => $value) {
if (0 === strpos($constantKey, 'OPT_')) {
if (str_starts_with($constantKey, 'OPT_')) {
$optionConstants[$constantKey] = $value;
}
}

View File

@@ -0,0 +1,33 @@
<?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;
/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
final class MysqliCaster
{
public static function castMysqliDriver(\mysqli_driver $c, array $a, Stub $stub, bool $isNested): array
{
foreach ($a as $k => $v) {
if (isset($c->$k)) {
$a[$k] = $c->$k;
}
}
return $a;
}
}

View File

@@ -17,56 +17,58 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts PDO related classes to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class PdoCaster
{
private static $pdoAttributes = array(
'CASE' => array(
private const PDO_ATTRIBUTES = [
'CASE' => [
\PDO::CASE_LOWER => 'LOWER',
\PDO::CASE_NATURAL => 'NATURAL',
\PDO::CASE_UPPER => 'UPPER',
),
'ERRMODE' => array(
],
'ERRMODE' => [
\PDO::ERRMODE_SILENT => 'SILENT',
\PDO::ERRMODE_WARNING => 'WARNING',
\PDO::ERRMODE_EXCEPTION => 'EXCEPTION',
),
],
'TIMEOUT',
'PREFETCH',
'AUTOCOMMIT',
'PERSISTENT',
'DRIVER_NAME',
'SERVER_INFO',
'ORACLE_NULLS' => array(
'ORACLE_NULLS' => [
\PDO::NULL_NATURAL => 'NATURAL',
\PDO::NULL_EMPTY_STRING => 'EMPTY_STRING',
\PDO::NULL_TO_STRING => 'TO_STRING',
),
],
'CLIENT_VERSION',
'SERVER_VERSION',
'STATEMENT_CLASS',
'EMULATE_PREPARES',
'CONNECTION_STATUS',
'STRINGIFY_FETCHES',
'DEFAULT_FETCH_MODE' => array(
'DEFAULT_FETCH_MODE' => [
\PDO::FETCH_ASSOC => 'ASSOC',
\PDO::FETCH_BOTH => 'BOTH',
\PDO::FETCH_LAZY => 'LAZY',
\PDO::FETCH_NUM => 'NUM',
\PDO::FETCH_OBJ => 'OBJ',
),
);
],
];
public static function castPdo(\PDO $c, array $a, Stub $stub, $isNested)
{
$attr = array();
$attr = [];
$errmode = $c->getAttribute(\PDO::ATTR_ERRMODE);
$c->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
foreach (self::$pdoAttributes as $k => $v) {
foreach (self::PDO_ATTRIBUTES as $k => $v) {
if (!isset($k[0])) {
$k = $v;
$v = array();
$v = [];
}
try {
@@ -85,11 +87,11 @@ class PdoCaster
}
$prefix = Caster::PREFIX_VIRTUAL;
$a += array(
$a += [
$prefix.'inTransaction' => method_exists($c, 'inTransaction'),
$prefix.'errorInfo' => $c->errorInfo(),
$prefix.'attributes' => new EnumStub($attr),
);
];
if ($a[$prefix.'inTransaction']) {
$a[$prefix.'inTransaction'] = $c->inTransaction();

View File

@@ -17,10 +17,12 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts pqsql resources to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class PgSqlCaster
{
private static $paramCodes = array(
private const PARAM_CODES = [
'server_encoding',
'client_encoding',
'is_superuser',
@@ -31,41 +33,41 @@ class PgSqlCaster
'integer_datetimes',
'application_name',
'standard_conforming_strings',
);
];
private static $transactionStatus = array(
PGSQL_TRANSACTION_IDLE => 'PGSQL_TRANSACTION_IDLE',
PGSQL_TRANSACTION_ACTIVE => 'PGSQL_TRANSACTION_ACTIVE',
PGSQL_TRANSACTION_INTRANS => 'PGSQL_TRANSACTION_INTRANS',
PGSQL_TRANSACTION_INERROR => 'PGSQL_TRANSACTION_INERROR',
PGSQL_TRANSACTION_UNKNOWN => 'PGSQL_TRANSACTION_UNKNOWN',
);
private const TRANSACTION_STATUS = [
\PGSQL_TRANSACTION_IDLE => 'PGSQL_TRANSACTION_IDLE',
\PGSQL_TRANSACTION_ACTIVE => 'PGSQL_TRANSACTION_ACTIVE',
\PGSQL_TRANSACTION_INTRANS => 'PGSQL_TRANSACTION_INTRANS',
\PGSQL_TRANSACTION_INERROR => 'PGSQL_TRANSACTION_INERROR',
\PGSQL_TRANSACTION_UNKNOWN => 'PGSQL_TRANSACTION_UNKNOWN',
];
private static $resultStatus = array(
PGSQL_EMPTY_QUERY => 'PGSQL_EMPTY_QUERY',
PGSQL_COMMAND_OK => 'PGSQL_COMMAND_OK',
PGSQL_TUPLES_OK => 'PGSQL_TUPLES_OK',
PGSQL_COPY_OUT => 'PGSQL_COPY_OUT',
PGSQL_COPY_IN => 'PGSQL_COPY_IN',
PGSQL_BAD_RESPONSE => 'PGSQL_BAD_RESPONSE',
PGSQL_NONFATAL_ERROR => 'PGSQL_NONFATAL_ERROR',
PGSQL_FATAL_ERROR => 'PGSQL_FATAL_ERROR',
);
private const RESULT_STATUS = [
\PGSQL_EMPTY_QUERY => 'PGSQL_EMPTY_QUERY',
\PGSQL_COMMAND_OK => 'PGSQL_COMMAND_OK',
\PGSQL_TUPLES_OK => 'PGSQL_TUPLES_OK',
\PGSQL_COPY_OUT => 'PGSQL_COPY_OUT',
\PGSQL_COPY_IN => 'PGSQL_COPY_IN',
\PGSQL_BAD_RESPONSE => 'PGSQL_BAD_RESPONSE',
\PGSQL_NONFATAL_ERROR => 'PGSQL_NONFATAL_ERROR',
\PGSQL_FATAL_ERROR => 'PGSQL_FATAL_ERROR',
];
private static $diagCodes = array(
'severity' => PGSQL_DIAG_SEVERITY,
'sqlstate' => PGSQL_DIAG_SQLSTATE,
'message' => PGSQL_DIAG_MESSAGE_PRIMARY,
'detail' => PGSQL_DIAG_MESSAGE_DETAIL,
'hint' => PGSQL_DIAG_MESSAGE_HINT,
'statement position' => PGSQL_DIAG_STATEMENT_POSITION,
'internal position' => PGSQL_DIAG_INTERNAL_POSITION,
'internal query' => PGSQL_DIAG_INTERNAL_QUERY,
'context' => PGSQL_DIAG_CONTEXT,
'file' => PGSQL_DIAG_SOURCE_FILE,
'line' => PGSQL_DIAG_SOURCE_LINE,
'function' => PGSQL_DIAG_SOURCE_FUNCTION,
);
private const DIAG_CODES = [
'severity' => \PGSQL_DIAG_SEVERITY,
'sqlstate' => \PGSQL_DIAG_SQLSTATE,
'message' => \PGSQL_DIAG_MESSAGE_PRIMARY,
'detail' => \PGSQL_DIAG_MESSAGE_DETAIL,
'hint' => \PGSQL_DIAG_MESSAGE_HINT,
'statement position' => \PGSQL_DIAG_STATEMENT_POSITION,
'internal position' => \PGSQL_DIAG_INTERNAL_POSITION,
'internal query' => \PGSQL_DIAG_INTERNAL_QUERY,
'context' => \PGSQL_DIAG_CONTEXT,
'file' => \PGSQL_DIAG_SOURCE_FILE,
'line' => \PGSQL_DIAG_SOURCE_LINE,
'function' => \PGSQL_DIAG_SOURCE_FUNCTION,
];
public static function castLargeObject($lo, array $a, Stub $stub, $isNested)
{
@@ -77,12 +79,12 @@ class PgSqlCaster
public static function castLink($link, array $a, Stub $stub, $isNested)
{
$a['status'] = pg_connection_status($link);
$a['status'] = new ConstStub(PGSQL_CONNECTION_OK === $a['status'] ? 'PGSQL_CONNECTION_OK' : 'PGSQL_CONNECTION_BAD', $a['status']);
$a['status'] = new ConstStub(\PGSQL_CONNECTION_OK === $a['status'] ? 'PGSQL_CONNECTION_OK' : 'PGSQL_CONNECTION_BAD', $a['status']);
$a['busy'] = pg_connection_busy($link);
$a['transaction'] = pg_transaction_status($link);
if (isset(self::$transactionStatus[$a['transaction']])) {
$a['transaction'] = new ConstStub(self::$transactionStatus[$a['transaction']], $a['transaction']);
if (isset(self::TRANSACTION_STATUS[$a['transaction']])) {
$a['transaction'] = new ConstStub(self::TRANSACTION_STATUS[$a['transaction']], $a['transaction']);
}
$a['pid'] = pg_get_pid($link);
@@ -94,7 +96,7 @@ class PgSqlCaster
$a['options'] = pg_options($link);
$a['version'] = pg_version($link);
foreach (self::$paramCodes as $v) {
foreach (self::PARAM_CODES as $v) {
if (false !== $s = pg_parameter_status($link, $v)) {
$a['param'][$v] = $s;
}
@@ -110,13 +112,13 @@ class PgSqlCaster
{
$a['num rows'] = pg_num_rows($result);
$a['status'] = pg_result_status($result);
if (isset(self::$resultStatus[$a['status']])) {
$a['status'] = new ConstStub(self::$resultStatus[$a['status']], $a['status']);
if (isset(self::RESULT_STATUS[$a['status']])) {
$a['status'] = new ConstStub(self::RESULT_STATUS[$a['status']], $a['status']);
}
$a['command-completion tag'] = pg_result_status($result, PGSQL_STATUS_STRING);
$a['command-completion tag'] = pg_result_status($result, \PGSQL_STATUS_STRING);
if (-1 === $a['num rows']) {
foreach (self::$diagCodes as $k => $v) {
foreach (self::DIAG_CODES as $k => $v) {
$a['error'][$k] = pg_result_error_field($result, $v);
}
}
@@ -127,14 +129,14 @@ class PgSqlCaster
$fields = pg_num_fields($result);
for ($i = 0; $i < $fields; ++$i) {
$field = array(
$field = [
'name' => pg_field_name($result, $i),
'table' => sprintf('%s (OID: %s)', pg_field_table($result, $i), pg_field_table($result, $i, true)),
'type' => sprintf('%s (OID: %s)', pg_field_type($result, $i), pg_field_type_oid($result, $i)),
'nullable' => (bool) pg_field_is_null($result, $i),
'storage' => pg_field_size($result, $i).' bytes',
'display' => pg_field_prtlen($result, $i).' chars',
);
];
if (' (OID: )' === $field['table']) {
$field['table'] = null;
}

View File

@@ -16,12 +16,14 @@ use Symfony\Component\VarDumper\Cloner\Stub;
/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class ProxyManagerCaster
{
public static function castProxy(ProxyInterface $c, array $a, Stub $stub, $isNested)
{
if ($parent = \get_parent_class($c)) {
if ($parent = get_parent_class($c)) {
$stub->class .= ' - '.$parent;
}
$stub->class .= '@proxy';

View File

@@ -17,69 +17,71 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts Redis class from ext-redis to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class RedisCaster
{
private static $serializer = array(
private const SERIALIZERS = [
\Redis::SERIALIZER_NONE => 'NONE',
\Redis::SERIALIZER_PHP => 'PHP',
2 => 'IGBINARY', // Optional Redis::SERIALIZER_IGBINARY
);
];
private static $mode = array(
private const MODES = [
\Redis::ATOMIC => 'ATOMIC',
\Redis::MULTI => 'MULTI',
\Redis::PIPELINE => 'PIPELINE',
);
];
private static $compression = array(
private const COMPRESSION_MODES = [
0 => 'NONE', // Redis::COMPRESSION_NONE
1 => 'LZF', // Redis::COMPRESSION_LZF
);
];
private static $failover = array(
private const FAILOVER_OPTIONS = [
\RedisCluster::FAILOVER_NONE => 'NONE',
\RedisCluster::FAILOVER_ERROR => 'ERROR',
\RedisCluster::FAILOVER_DISTRIBUTE => 'DISTRIBUTE',
\RedisCluster::FAILOVER_DISTRIBUTE_SLAVES => 'DISTRIBUTE_SLAVES',
);
];
public static function castRedis(\Redis $c, array $a, Stub $stub, $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
if (!$connected = $c->isConnected()) {
return $a + array(
return $a + [
$prefix.'isConnected' => $connected,
);
];
}
$mode = $c->getMode();
return $a + array(
return $a + [
$prefix.'isConnected' => $connected,
$prefix.'host' => $c->getHost(),
$prefix.'port' => $c->getPort(),
$prefix.'auth' => $c->getAuth(),
$prefix.'mode' => isset(self::$mode[$mode]) ? new ConstStub(self::$mode[$mode], $mode) : $mode,
$prefix.'mode' => isset(self::MODES[$mode]) ? new ConstStub(self::MODES[$mode], $mode) : $mode,
$prefix.'dbNum' => $c->getDbNum(),
$prefix.'timeout' => $c->getTimeout(),
$prefix.'lastError' => $c->getLastError(),
$prefix.'persistentId' => $c->getPersistentID(),
$prefix.'options' => self::getRedisOptions($c),
);
];
}
public static function castRedisArray(\RedisArray $c, array $a, Stub $stub, $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
return $a + array(
return $a + [
$prefix.'hosts' => $c->_hosts(),
$prefix.'function' => ClassStub::wrapCallable($c->_function()),
$prefix.'lastError' => $c->getLastError(),
$prefix.'options' => self::getRedisOptions($c),
);
];
}
public static function castRedisCluster(\RedisCluster $c, array $a, Stub $stub, $isNested)
@@ -87,15 +89,15 @@ class RedisCaster
$prefix = Caster::PREFIX_VIRTUAL;
$failover = $c->getOption(\RedisCluster::OPT_SLAVE_FAILOVER);
$a += array(
$a += [
$prefix.'_masters' => $c->_masters(),
$prefix.'_redir' => $c->_redir(),
$prefix.'mode' => new ConstStub($c->getMode() ? 'MULTI' : 'ATOMIC', $c->getMode()),
$prefix.'lastError' => $c->getLastError(),
$prefix.'options' => self::getRedisOptions($c, array(
'SLAVE_FAILOVER' => isset(self::$failover[$failover]) ? new ConstStub(self::$failover[$failover], $failover) : $failover,
)),
);
$prefix.'options' => self::getRedisOptions($c, [
'SLAVE_FAILOVER' => isset(self::FAILOVER_OPTIONS[$failover]) ? new ConstStub(self::FAILOVER_OPTIONS[$failover], $failover) : $failover,
]),
];
return $a;
}
@@ -103,28 +105,28 @@ class RedisCaster
/**
* @param \Redis|\RedisArray|\RedisCluster $redis
*/
private static function getRedisOptions($redis, array $options = array()): EnumStub
private static function getRedisOptions($redis, array $options = []): EnumStub
{
$serializer = $redis->getOption(\Redis::OPT_SERIALIZER);
if (\is_array($serializer)) {
foreach ($serializer as &$v) {
if (isset(self::$serializer[$v])) {
$v = new ConstStub(self::$serializer[$v], $v);
if (isset(self::SERIALIZERS[$v])) {
$v = new ConstStub(self::SERIALIZERS[$v], $v);
}
}
} elseif (isset(self::$serializer[$serializer])) {
$serializer = new ConstStub(self::$serializer[$serializer], $serializer);
} elseif (isset(self::SERIALIZERS[$serializer])) {
$serializer = new ConstStub(self::SERIALIZERS[$serializer], $serializer);
}
$compression = \defined('Redis::OPT_COMPRESSION') ? $redis->getOption(\Redis::OPT_COMPRESSION) : 0;
if (\is_array($compression)) {
foreach ($compression as &$v) {
if (isset(self::$compression[$v])) {
$v = new ConstStub(self::$compression[$v], $v);
if (isset(self::COMPRESSION_MODES[$v])) {
$v = new ConstStub(self::COMPRESSION_MODES[$v], $v);
}
}
} elseif (isset(self::$compression[$compression])) {
$compression = new ConstStub(self::$compression[$compression], $compression);
} elseif (isset(self::COMPRESSION_MODES[$compression])) {
$compression = new ConstStub(self::COMPRESSION_MODES[$compression], $compression);
}
$retry = \defined('Redis::OPT_SCAN') ? $redis->getOption(\Redis::OPT_SCAN) : 0;
@@ -136,14 +138,14 @@ class RedisCaster
$retry = new ConstStub($retry ? 'RETRY' : 'NORETRY', $retry);
}
$options += array(
$options += [
'TCP_KEEPALIVE' => \defined('Redis::OPT_TCP_KEEPALIVE') ? $redis->getOption(\Redis::OPT_TCP_KEEPALIVE) : 0,
'READ_TIMEOUT' => $redis->getOption(\Redis::OPT_READ_TIMEOUT),
'COMPRESSION' => $compression,
'SERIALIZER' => $serializer,
'PREFIX' => $redis->getOption(\Redis::OPT_PREFIX),
'SCAN' => $retry,
);
];
return new EnumStub($options);
}

View File

@@ -17,10 +17,14 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts Reflector related classes to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class ReflectionCaster
{
private static $extraMap = array(
public const UNSET_CLOSURE_FILE_INFO = ['Closure' => __CLASS__.'::unsetClosureFileInfo'];
private const EXTRA_MAP = [
'docComment' => 'getDocComment',
'extension' => 'getExtensionName',
'isDisabled' => 'isDisabled',
@@ -29,7 +33,7 @@ class ReflectionCaster
'isUserDefined' => 'isUserDefined',
'isGenerator' => 'isGenerator',
'isVariadic' => 'isVariadic',
);
];
public static function castClosure(\Closure $c, array $a, Stub $stub, $isNested, $filter = 0)
{
@@ -38,7 +42,7 @@ class ReflectionCaster
$a = static::castFunctionAbstract($c, $a, $stub, $isNested, $filter);
if (false === strpos($c->name, '{closure}')) {
if (!str_contains($c->name, '{closure}')) {
$stub->class = isset($a[$prefix.'class']) ? $a[$prefix.'class']->value.'::'.$c->name : $c->name;
unset($a[$prefix.'class']);
}
@@ -46,26 +50,20 @@ class ReflectionCaster
$stub->class .= self::getSignature($a);
if ($f = $c->getFileName()) {
$stub->attr['file'] = $f;
$stub->attr['line'] = $c->getStartLine();
}
unset($a[$prefix.'parameters']);
if ($filter & Caster::EXCLUDE_VERBOSE) {
$stub->cut += ($c->getFileName() ? 2 : 0) + \count($a);
return array();
return [];
}
if (isset($a[$prefix.'parameters'])) {
foreach ($a[$prefix.'parameters']->value as &$v) {
$param = $v;
$v = new EnumStub(array());
foreach (static::castParameter($param, array(), $stub, true) as $k => $param) {
if ("\0" === $k[0]) {
$v->value[substr($k, 3)] = $param;
}
}
unset($v->value['position'], $v->value['isVariadic'], $v->value['byReference'], $v);
}
}
if ($f = $c->getFileName()) {
if ($f) {
$a[$prefix.'file'] = new LinkStub($f, $c->getStartLine());
$a[$prefix.'line'] = $c->getStartLine().' to '.$c->getEndLine();
}
@@ -73,12 +71,15 @@ class ReflectionCaster
return $a;
}
public static function unsetClosureFileInfo(\Closure $c, array $a)
{
unset($a[Caster::PREFIX_VIRTUAL.'file'], $a[Caster::PREFIX_VIRTUAL.'line']);
return $a;
}
public static function castGenerator(\Generator $c, array $a, Stub $stub, $isNested)
{
if (!class_exists('ReflectionGenerator', false)) {
return $a;
}
// Cannot create ReflectionGenerator based on a terminated Generator
try {
$reflectionGenerator = new \ReflectionGenerator($c);
@@ -95,11 +96,20 @@ class ReflectionCaster
{
$prefix = Caster::PREFIX_VIRTUAL;
$a += array(
$prefix.'name' => $c->getName(),
$prefix.'allowsNull' => $c->allowsNull(),
$prefix.'isBuiltin' => $c->isBuiltin(),
);
if ($c instanceof \ReflectionNamedType || \PHP_VERSION_ID < 80000) {
$a += [
$prefix.'name' => $c instanceof \ReflectionNamedType ? $c->getName() : (string) $c,
$prefix.'allowsNull' => $c->allowsNull(),
$prefix.'isBuiltin' => $c->isBuiltin(),
];
} elseif ($c instanceof \ReflectionUnionType || $c instanceof \ReflectionIntersectionType) {
$a[$prefix.'allowsNull'] = $c->allowsNull();
self::addMap($a, $c, [
'types' => 'getTypes',
]);
} else {
$a[$prefix.'allowsNull'] = $c->allowsNull();
}
return $a;
}
@@ -112,28 +122,26 @@ class ReflectionCaster
$a[$prefix.'this'] = new CutStub($c->getThis());
}
$function = $c->getFunction();
$frame = array(
'class' => isset($function->class) ? $function->class : null,
$frame = [
'class' => $function->class ?? null,
'type' => isset($function->class) ? ($function->isStatic() ? '::' : '->') : null,
'function' => $function->name,
'file' => $c->getExecutingFile(),
'line' => $c->getExecutingLine(),
);
if ($trace = $c->getTrace(DEBUG_BACKTRACE_IGNORE_ARGS)) {
];
if ($trace = $c->getTrace(\DEBUG_BACKTRACE_IGNORE_ARGS)) {
$function = new \ReflectionGenerator($c->getExecutingGenerator());
array_unshift($trace, array(
array_unshift($trace, [
'function' => 'yield',
'file' => $function->getExecutingFile(),
'line' => $function->getExecutingLine() - 1,
));
'line' => $function->getExecutingLine() - (int) (\PHP_VERSION_ID < 80100),
]);
$trace[] = $frame;
$a[$prefix.'trace'] = new TraceStub($trace, false, 0, -1, -1);
} else {
$function = new FrameStub($frame, false, true);
$function = ExceptionCaster::castFrameStub($function, array(), $function, true);
$a[$prefix.'executing'] = new EnumStub(array(
"\0~separator= \0".$frame['class'].$frame['type'].$frame['function'].'()' => $function[$prefix.'src'],
));
$function = ExceptionCaster::castFrameStub($function, [], $function, true);
$a[$prefix.'executing'] = $function[$prefix.'src'];
}
$a[Caster::PREFIX_VIRTUAL.'closed'] = false;
@@ -149,11 +157,11 @@ class ReflectionCaster
$a[$prefix.'modifiers'] = implode(' ', $n);
}
self::addMap($a, $c, array(
self::addMap($a, $c, [
'extends' => 'getParentClass',
'implements' => 'getInterfaceNames',
'constants' => 'getConstants',
));
]);
foreach ($c->getProperties() as $n) {
$a[$prefix.'properties'][$n->name] = $n;
@@ -174,17 +182,17 @@ class ReflectionCaster
{
$prefix = Caster::PREFIX_VIRTUAL;
self::addMap($a, $c, array(
self::addMap($a, $c, [
'returnsReference' => 'returnsReference',
'returnType' => 'getReturnType',
'class' => 'getClosureScopeClass',
'this' => 'getClosureThis',
));
]);
if (isset($a[$prefix.'returnType'])) {
$v = $a[$prefix.'returnType'];
$v = $v->getName();
$a[$prefix.'returnType'] = new ClassStub($a[$prefix.'returnType']->allowsNull() ? '?'.$v : $v, array(class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', ''));
$v = $v instanceof \ReflectionNamedType ? $v->getName() : (string) $v;
$a[$prefix.'returnType'] = new ClassStub($a[$prefix.'returnType'] instanceof \ReflectionNamedType && $a[$prefix.'returnType']->allowsNull() && 'mixed' !== $v ? '?'.$v : $v, [class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '']);
}
if (isset($a[$prefix.'class'])) {
$a[$prefix.'class'] = new ClassStub($a[$prefix.'class']);
@@ -207,7 +215,7 @@ class ReflectionCaster
$a[$prefix.'parameters'] = new EnumStub($a[$prefix.'parameters']);
}
if ($v = $c->getStaticVariables()) {
if (!($filter & Caster::EXCLUDE_VERBOSE) && $v = $c->getStaticVariables()) {
foreach ($v as $k => &$v) {
if (\is_object($v)) {
$a[$prefix.'use']['$'.$k] = new CutStub($v);
@@ -237,33 +245,35 @@ class ReflectionCaster
{
$prefix = Caster::PREFIX_VIRTUAL;
self::addMap($a, $c, array(
self::addMap($a, $c, [
'position' => 'getPosition',
'isVariadic' => 'isVariadic',
'byReference' => 'isPassedByReference',
'allowsNull' => 'allowsNull',
));
]);
if ($v = $c->getType()) {
$a[$prefix.'typeHint'] = $v->getName();
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : (string) $v;
}
if (isset($a[$prefix.'typeHint'])) {
$v = $a[$prefix.'typeHint'];
$a[$prefix.'typeHint'] = new ClassStub($v, array(class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', ''));
$a[$prefix.'typeHint'] = new ClassStub($v, [class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '']);
} else {
unset($a[$prefix.'allowsNull']);
}
try {
$a[$prefix.'default'] = $v = $c->getDefaultValue();
if ($c->isDefaultValueConstant()) {
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
if ($c->isOptional()) {
try {
$a[$prefix.'default'] = $v = $c->getDefaultValue();
if ($c->isDefaultValueConstant()) {
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
}
if (null === $v) {
unset($a[$prefix.'allowsNull']);
}
} catch (\ReflectionException $e) {
}
if (null === $v) {
unset($a[$prefix.'allowsNull']);
}
} catch (\ReflectionException $e) {
}
return $a;
@@ -277,9 +287,16 @@ class ReflectionCaster
return $a;
}
public static function castReference(\ReflectionReference $c, array $a, Stub $stub, $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'id'] = $c->getId();
return $a;
}
public static function castExtension(\ReflectionExtension $c, array $a, Stub $stub, $isNested)
{
self::addMap($a, $c, array(
self::addMap($a, $c, [
'version' => 'getVersion',
'dependencies' => 'getDependencies',
'iniEntries' => 'getIniEntries',
@@ -288,19 +305,19 @@ class ReflectionCaster
'constants' => 'getConstants',
'functions' => 'getFunctions',
'classes' => 'getClasses',
));
]);
return $a;
}
public static function castZendExtension(\ReflectionZendExtension $c, array $a, Stub $stub, $isNested)
{
self::addMap($a, $c, array(
self::addMap($a, $c, [
'version' => 'getVersion',
'author' => 'getAuthor',
'copyright' => 'getCopyright',
'url' => 'getURL',
));
]);
return $a;
}
@@ -314,10 +331,14 @@ class ReflectionCaster
foreach ($a[$prefix.'parameters']->value as $k => $param) {
$signature .= ', ';
if ($type = $param->getType()) {
if (!$param->isOptional() && $param->allowsNull()) {
$signature .= '?';
if (!$type instanceof \ReflectionNamedType) {
$signature .= $type.' ';
} else {
if (!$param->isOptional() && $param->allowsNull() && 'mixed' !== $type->getName()) {
$signature .= '?';
}
$signature .= substr(strrchr('\\'.$type->getName(), '\\'), 1).' ';
}
$signature .= substr(strrchr('\\'.$type->getName(), '\\'), 1).' ';
}
$signature .= $k;
@@ -334,9 +355,11 @@ class ReflectionCaster
} elseif (\is_array($v)) {
$signature .= $v ? '[…'.\count($v).']' : '[]';
} elseif (\is_string($v)) {
$signature .= 10 > \strlen($v) && false === strpos($v, '\\') ? "'{$v}'" : "'…".\strlen($v)."'";
$signature .= 10 > \strlen($v) && !str_contains($v, '\\') ? "'{$v}'" : "'…".\strlen($v)."'";
} elseif (\is_bool($v)) {
$signature .= $v ? 'true' : 'false';
} elseif (\is_object($v)) {
$signature .= 'new '.substr(strrchr('\\'.get_debug_type($v), '\\'), 1);
} else {
$signature .= $v;
}
@@ -351,25 +374,29 @@ class ReflectionCaster
return $signature;
}
private static function addExtra(&$a, \Reflector $c)
private static function addExtra(array &$a, \Reflector $c)
{
$x = isset($a[Caster::PREFIX_VIRTUAL.'extra']) ? $a[Caster::PREFIX_VIRTUAL.'extra']->value : array();
$x = isset($a[Caster::PREFIX_VIRTUAL.'extra']) ? $a[Caster::PREFIX_VIRTUAL.'extra']->value : [];
if (method_exists($c, 'getFileName') && $m = $c->getFileName()) {
$x['file'] = new LinkStub($m, $c->getStartLine());
$x['line'] = $c->getStartLine().' to '.$c->getEndLine();
}
self::addMap($x, $c, self::$extraMap, '');
self::addMap($x, $c, self::EXTRA_MAP, '');
if ($x) {
$a[Caster::PREFIX_VIRTUAL.'extra'] = new EnumStub($x);
}
}
private static function addMap(&$a, \Reflector $c, $map, $prefix = Caster::PREFIX_VIRTUAL)
private static function addMap(array &$a, $c, array $map, string $prefix = Caster::PREFIX_VIRTUAL)
{
foreach ($map as $k => $m) {
if (\PHP_VERSION_ID >= 80000 && 'isDisabled' === $k) {
continue;
}
if (method_exists($c, $m) && false !== ($m = $c->$m()) && null !== $m) {
$a[$prefix.$k] = $m instanceof \Reflector ? $m->name : $m;
}

View File

@@ -17,9 +17,16 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts common resource types to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class ResourceCaster
{
/**
* @param \CurlHandle|resource $h
*
* @return array
*/
public static function castCurl($h, array $a, Stub $stub, $isNested)
{
return curl_getinfo($h);
@@ -41,7 +48,7 @@ class ResourceCaster
public static function castStream($stream, array $a, Stub $stub, $isNested)
{
$a = stream_get_meta_data($stream) + static::castStreamContext($stream, $a, $stub, $isNested);
if (isset($a['uri'])) {
if ($a['uri'] ?? false) {
$a['uri'] = new LinkStub($a['uri']);
}
@@ -69,4 +76,30 @@ class ResourceCaster
return $a;
}
public static function castOpensslX509($h, array $a, Stub $stub, $isNested)
{
$stub->cut = -1;
$info = openssl_x509_parse($h, false);
$pin = openssl_pkey_get_public($h);
$pin = openssl_pkey_get_details($pin)['key'];
$pin = \array_slice(explode("\n", $pin), 1, -2);
$pin = base64_decode(implode('', $pin));
$pin = base64_encode(hash('sha256', $pin, true));
$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']),
'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)),
'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)),
'pin-sha256' => new ConstStub($pin),
]),
];
return $a;
}
}

View File

@@ -17,15 +17,17 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts SPL related classes to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class SplCaster
{
private static $splFileObjectFlags = array(
private const SPL_FILE_OBJECT_FLAGS = [
\SplFileObject::DROP_NEW_LINE => 'DROP_NEW_LINE',
\SplFileObject::READ_AHEAD => 'READ_AHEAD',
\SplFileObject::SKIP_EMPTY => 'SKIP_EMPTY',
\SplFileObject::READ_CSV => 'READ_CSV',
);
];
public static function castArrayObject(\ArrayObject $c, array $a, Stub $stub, $isNested)
{
@@ -39,9 +41,9 @@ class SplCaster
public static function castHeap(\Iterator $c, array $a, Stub $stub, $isNested)
{
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'heap' => iterator_to_array(clone $c),
);
];
return $a;
}
@@ -52,10 +54,10 @@ class SplCaster
$mode = $c->getIteratorMode();
$c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP | $mode & ~\SplDoublyLinkedList::IT_MODE_DELETE);
$a += array(
$a += [
$prefix.'mode' => new ConstStub((($mode & \SplDoublyLinkedList::IT_MODE_LIFO) ? 'IT_MODE_LIFO' : 'IT_MODE_FIFO').' | '.(($mode & \SplDoublyLinkedList::IT_MODE_DELETE) ? 'IT_MODE_DELETE' : 'IT_MODE_KEEP'), $mode),
$prefix.'dllist' => iterator_to_array($c),
);
];
$c->setIteratorMode($mode);
return $a;
@@ -63,7 +65,7 @@ class SplCaster
public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNested)
{
static $map = array(
static $map = [
'path' => 'getPath',
'filename' => 'getFilename',
'basename' => 'getBasename',
@@ -86,9 +88,39 @@ class SplCaster
'dir' => 'isDir',
'link' => 'isLink',
'linkTarget' => 'getLinkTarget',
);
];
$prefix = Caster::PREFIX_VIRTUAL;
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;
}
} 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';
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 {
@@ -97,7 +129,7 @@ class SplCaster
}
}
if (isset($a[$prefix.'realPath'])) {
if ($a[$prefix.'realPath'] ?? false) {
$a[$prefix.'realPath'] = new LinkStub($a[$prefix.'realPath']);
}
@@ -105,7 +137,7 @@ class SplCaster
$a[$prefix.'perms'] = new ConstStub(sprintf('0%o', $a[$prefix.'perms']), $a[$prefix.'perms']);
}
static $mapDate = array('aTime', 'mTime', 'cTime');
static $mapDate = ['aTime', 'mTime', 'cTime'];
foreach ($mapDate as $key) {
if (isset($a[$prefix.$key])) {
$a[$prefix.$key] = new ConstStub(date('Y-m-d H:i:s', $a[$prefix.$key]), $a[$prefix.$key]);
@@ -117,14 +149,14 @@ class SplCaster
public static function castFileObject(\SplFileObject $c, array $a, Stub $stub, $isNested)
{
static $map = array(
static $map = [
'csvControl' => 'getCsvControl',
'flags' => 'getFlags',
'maxLineLen' => 'getMaxLineLen',
'fstat' => 'fstat',
'eof' => 'eof',
'key' => 'key',
);
];
$prefix = Caster::PREFIX_VIRTUAL;
@@ -136,8 +168,8 @@ class SplCaster
}
if (isset($a[$prefix.'flags'])) {
$flagsArray = array();
foreach (self::$splFileObjectFlags as $value => $name) {
$flagsArray = [];
foreach (self::SPL_FILE_OBJECT_FLAGS as $value => $name) {
if ($a[$prefix.'flags'] & $value) {
$flagsArray[] = $name;
}
@@ -146,37 +178,29 @@ class SplCaster
}
if (isset($a[$prefix.'fstat'])) {
$a[$prefix.'fstat'] = new CutArrayStub($a[$prefix.'fstat'], array('dev', 'ino', 'nlink', 'rdev', 'blksize', 'blocks'));
$a[$prefix.'fstat'] = new CutArrayStub($a[$prefix.'fstat'], ['dev', 'ino', 'nlink', 'rdev', 'blksize', 'blocks']);
}
return $a;
}
public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested)
{
$a += array(
Caster::PREFIX_VIRTUAL.'storage' => $c->toArray(),
);
return $a;
}
public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $stub, $isNested)
{
$storage = array();
$storage = [];
unset($a[Caster::PREFIX_DYNAMIC."\0gcdata"]); // Don't hit https://bugs.php.net/65967
unset($a["\0SplObjectStorage\0storage"]);
$clone = clone $c;
foreach ($clone as $obj) {
$storage[] = array(
$storage[] = [
'object' => $obj,
'info' => $clone->getInfo(),
);
];
}
$a += array(
$a += [
Caster::PREFIX_VIRTUAL.'storage' => $storage,
);
];
return $a;
}
@@ -188,25 +212,33 @@ class SplCaster
return $a;
}
private static function castSplArray($c, array $a, Stub $stub, $isNested)
public static function castWeakReference(\WeakReference $c, array $a, Stub $stub, $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'object'] = $c->get();
return $a;
}
private static function castSplArray($c, array $a, Stub $stub, bool $isNested): array
{
$prefix = Caster::PREFIX_VIRTUAL;
$class = $stub->class;
$flags = $c->getFlags();
if (!($flags & \ArrayObject::STD_PROP_LIST)) {
$c->setFlags(\ArrayObject::STD_PROP_LIST);
$a = Caster::castObject($c, $class);
$a = Caster::castObject($c, \get_class($c), method_exists($c, '__debugInfo'), $stub->class);
$c->setFlags($flags);
}
$a += array(
if (\PHP_VERSION_ID < 70400) {
$a[$prefix.'storage'] = $c->getArrayCopy();
}
$a += [
$prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST),
$prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS),
);
];
if ($c instanceof \ArrayObject) {
$a[$prefix.'iteratorClass'] = new ClassStub($c->getIteratorClass());
}
$a[$prefix.'storage'] = $c->getArrayCopy();
return $a;
}

View File

@@ -17,6 +17,8 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts a caster's Stub.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class StubCaster
{
@@ -35,7 +37,7 @@ class StubCaster
$stub->class = Stub::STRING_BINARY;
}
$a = array();
$a = [];
}
return $a;
@@ -51,7 +53,7 @@ class StubCaster
if ($isNested) {
$stub->cut += \count($a);
return array();
return [];
}
return $a;
@@ -66,7 +68,7 @@ class StubCaster
$stub->cut = $c->cut;
$stub->attr = $c->attr;
$a = array();
$a = [];
if ($c->value) {
foreach (array_keys($c->value) as $k) {

View File

@@ -14,23 +14,27 @@ namespace Symfony\Component\VarDumper\Caster;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\VarDumper\Cloner\Stub;
/**
* @final since Symfony 4.4
*/
class SymfonyCaster
{
private static $requestGetters = array(
private const REQUEST_GETTERS = [
'pathInfo' => 'getPathInfo',
'requestUri' => 'getRequestUri',
'baseUrl' => 'getBaseUrl',
'basePath' => 'getBasePath',
'method' => 'getMethod',
'format' => 'getRequestFormat',
);
];
public static function castRequest(Request $request, array $a, Stub $stub, $isNested)
{
$clone = null;
foreach (self::$requestGetters as $prop => $getter) {
if (null === $a[Caster::PREFIX_PROTECTED.$prop]) {
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;
}
@@ -40,4 +44,26 @@ class SymfonyCaster
return $a;
}
public static function castHttpClient($client, array $a, Stub $stub, $isNested)
{
$multiKey = sprintf("\0%s\0multi", \get_class($client));
if (isset($a[$multiKey])) {
$a[$multiKey] = new CutStub($a[$multiKey]);
}
return $a;
}
public static function castHttpClientResponse($response, array $a, Stub $stub, $isNested)
{
$stub->cut += \count($a);
$a = [];
foreach ($response->getInfo() as $k => $v) {
$a[Caster::PREFIX_VIRTUAL.$k] = $v;
}
return $a;
}
}

View File

@@ -0,0 +1,30 @@
<?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 Ramsey\Uuid\UuidInterface;
use Symfony\Component\VarDumper\Cloner\Stub;
/**
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
final class UuidCaster
{
public static function castRamseyUuid(UuidInterface $c, array $a, Stub $stub, bool $isNested): array
{
$a += [
Caster::PREFIX_VIRTUAL.'uuid' => (string) $c,
];
return $a;
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* This file is part of the Symfony package.
*
@@ -16,10 +17,12 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts XmlReader class to array representation.
*
* @author Baptiste Clavié <clavie.b@gmail.com>
*
* @final since Symfony 4.4
*/
class XmlReaderCaster
{
private static $nodeTypes = array(
private const NODE_TYPES = [
\XMLReader::NONE => 'NONE',
\XMLReader::ELEMENT => 'ELEMENT',
\XMLReader::ATTRIBUTE => 'ATTRIBUTE',
@@ -38,15 +41,31 @@ class XmlReaderCaster
\XMLReader::END_ELEMENT => 'END_ELEMENT',
\XMLReader::END_ENTITY => 'END_ENTITY',
\XMLReader::XML_DECLARATION => 'XML_DECLARATION',
);
];
public static function castXmlReader(\XMLReader $reader, array $a, Stub $stub, $isNested)
{
try {
$properties = [
'LOADDTD' => @$reader->getParserProperty(\XMLReader::LOADDTD),
'DEFAULTATTRS' => @$reader->getParserProperty(\XMLReader::DEFAULTATTRS),
'VALIDATE' => @$reader->getParserProperty(\XMLReader::VALIDATE),
'SUBST_ENTITIES' => @$reader->getParserProperty(\XMLReader::SUBST_ENTITIES),
];
} catch (\Error $e) {
$properties = [
'LOADDTD' => false,
'DEFAULTATTRS' => false,
'VALIDATE' => false,
'SUBST_ENTITIES' => false,
];
}
$props = Caster::PREFIX_VIRTUAL.'parserProperties';
$info = array(
$info = [
'localName' => $reader->localName,
'prefix' => $reader->prefix,
'nodeType' => new ConstStub(self::$nodeTypes[$reader->nodeType], $reader->nodeType),
'nodeType' => new ConstStub(self::NODE_TYPES[$reader->nodeType], $reader->nodeType),
'depth' => $reader->depth,
'isDefault' => $reader->isDefault,
'isEmptyElement' => \XMLReader::NONE === $reader->nodeType ? null : $reader->isEmptyElement,
@@ -55,20 +74,15 @@ class XmlReaderCaster
'value' => $reader->value,
'namespaceURI' => $reader->namespaceURI,
'baseURI' => $reader->baseURI ? new LinkStub($reader->baseURI) : $reader->baseURI,
$props => array(
'LOADDTD' => $reader->getParserProperty(\XMLReader::LOADDTD),
'DEFAULTATTRS' => $reader->getParserProperty(\XMLReader::DEFAULTATTRS),
'VALIDATE' => $reader->getParserProperty(\XMLReader::VALIDATE),
'SUBST_ENTITIES' => $reader->getParserProperty(\XMLReader::SUBST_ENTITIES),
),
);
$props => $properties,
];
if ($info[$props] = Caster::filter($info[$props], Caster::EXCLUDE_EMPTY, array(), $count)) {
if ($info[$props] = Caster::filter($info[$props], Caster::EXCLUDE_EMPTY, [], $count)) {
$info[$props] = new EnumStub($info[$props]);
$info[$props]->cut = $count;
}
$info = Caster::filter($info, Caster::EXCLUDE_EMPTY, array(), $count);
$info = Caster::filter($info, Caster::EXCLUDE_EMPTY, [], $count);
// +2 because hasValue and hasAttributes are always filtered
$stub->cut += $count + 2;

View File

@@ -17,33 +17,35 @@ use Symfony\Component\VarDumper\Cloner\Stub;
* Casts XML resources to array representation.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
*/
class XmlResourceCaster
{
private static $xmlErrors = array(
XML_ERROR_NONE => 'XML_ERROR_NONE',
XML_ERROR_NO_MEMORY => 'XML_ERROR_NO_MEMORY',
XML_ERROR_SYNTAX => 'XML_ERROR_SYNTAX',
XML_ERROR_NO_ELEMENTS => 'XML_ERROR_NO_ELEMENTS',
XML_ERROR_INVALID_TOKEN => 'XML_ERROR_INVALID_TOKEN',
XML_ERROR_UNCLOSED_TOKEN => 'XML_ERROR_UNCLOSED_TOKEN',
XML_ERROR_PARTIAL_CHAR => 'XML_ERROR_PARTIAL_CHAR',
XML_ERROR_TAG_MISMATCH => 'XML_ERROR_TAG_MISMATCH',
XML_ERROR_DUPLICATE_ATTRIBUTE => 'XML_ERROR_DUPLICATE_ATTRIBUTE',
XML_ERROR_JUNK_AFTER_DOC_ELEMENT => 'XML_ERROR_JUNK_AFTER_DOC_ELEMENT',
XML_ERROR_PARAM_ENTITY_REF => 'XML_ERROR_PARAM_ENTITY_REF',
XML_ERROR_UNDEFINED_ENTITY => 'XML_ERROR_UNDEFINED_ENTITY',
XML_ERROR_RECURSIVE_ENTITY_REF => 'XML_ERROR_RECURSIVE_ENTITY_REF',
XML_ERROR_ASYNC_ENTITY => 'XML_ERROR_ASYNC_ENTITY',
XML_ERROR_BAD_CHAR_REF => 'XML_ERROR_BAD_CHAR_REF',
XML_ERROR_BINARY_ENTITY_REF => 'XML_ERROR_BINARY_ENTITY_REF',
XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF => 'XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF',
XML_ERROR_MISPLACED_XML_PI => 'XML_ERROR_MISPLACED_XML_PI',
XML_ERROR_UNKNOWN_ENCODING => 'XML_ERROR_UNKNOWN_ENCODING',
XML_ERROR_INCORRECT_ENCODING => 'XML_ERROR_INCORRECT_ENCODING',
XML_ERROR_UNCLOSED_CDATA_SECTION => 'XML_ERROR_UNCLOSED_CDATA_SECTION',
XML_ERROR_EXTERNAL_ENTITY_HANDLING => 'XML_ERROR_EXTERNAL_ENTITY_HANDLING',
);
private const XML_ERRORS = [
\XML_ERROR_NONE => 'XML_ERROR_NONE',
\XML_ERROR_NO_MEMORY => 'XML_ERROR_NO_MEMORY',
\XML_ERROR_SYNTAX => 'XML_ERROR_SYNTAX',
\XML_ERROR_NO_ELEMENTS => 'XML_ERROR_NO_ELEMENTS',
\XML_ERROR_INVALID_TOKEN => 'XML_ERROR_INVALID_TOKEN',
\XML_ERROR_UNCLOSED_TOKEN => 'XML_ERROR_UNCLOSED_TOKEN',
\XML_ERROR_PARTIAL_CHAR => 'XML_ERROR_PARTIAL_CHAR',
\XML_ERROR_TAG_MISMATCH => 'XML_ERROR_TAG_MISMATCH',
\XML_ERROR_DUPLICATE_ATTRIBUTE => 'XML_ERROR_DUPLICATE_ATTRIBUTE',
\XML_ERROR_JUNK_AFTER_DOC_ELEMENT => 'XML_ERROR_JUNK_AFTER_DOC_ELEMENT',
\XML_ERROR_PARAM_ENTITY_REF => 'XML_ERROR_PARAM_ENTITY_REF',
\XML_ERROR_UNDEFINED_ENTITY => 'XML_ERROR_UNDEFINED_ENTITY',
\XML_ERROR_RECURSIVE_ENTITY_REF => 'XML_ERROR_RECURSIVE_ENTITY_REF',
\XML_ERROR_ASYNC_ENTITY => 'XML_ERROR_ASYNC_ENTITY',
\XML_ERROR_BAD_CHAR_REF => 'XML_ERROR_BAD_CHAR_REF',
\XML_ERROR_BINARY_ENTITY_REF => 'XML_ERROR_BINARY_ENTITY_REF',
\XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF => 'XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF',
\XML_ERROR_MISPLACED_XML_PI => 'XML_ERROR_MISPLACED_XML_PI',
\XML_ERROR_UNKNOWN_ENCODING => 'XML_ERROR_UNKNOWN_ENCODING',
\XML_ERROR_INCORRECT_ENCODING => 'XML_ERROR_INCORRECT_ENCODING',
\XML_ERROR_UNCLOSED_CDATA_SECTION => 'XML_ERROR_UNCLOSED_CDATA_SECTION',
\XML_ERROR_EXTERNAL_ENTITY_HANDLING => 'XML_ERROR_EXTERNAL_ENTITY_HANDLING',
];
public static function castXml($h, array $a, Stub $stub, $isNested)
{
@@ -52,8 +54,8 @@ class XmlResourceCaster
$a['current_line_number'] = xml_get_current_line_number($h);
$a['error_code'] = xml_get_error_code($h);
if (isset(self::$xmlErrors[$a['error_code']])) {
$a['error_code'] = new ConstStub(self::$xmlErrors[$a['error_code']], $a['error_code']);
if (isset(self::XML_ERRORS[$a['error_code']])) {
$a['error_code'] = new ConstStub(self::XML_ERRORS[$a['error_code']], $a['error_code']);
}
return $a;