updated-packages
This commit is contained in:
117
vendor/symfony/var-dumper/Cloner/Data.php
vendored
117
vendor/symfony/var-dumper/Cloner/Data.php
vendored
@@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\VarDumper\Cloner;
|
||||
|
||||
use Symfony\Component\VarDumper\Caster\Caster;
|
||||
use Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
@@ -24,6 +25,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
private $maxDepth = 20;
|
||||
private $maxItemsPerDepth = -1;
|
||||
private $useRefHandles = -1;
|
||||
private $context = [];
|
||||
|
||||
/**
|
||||
* @param array $data An array as returned by ClonerInterface::cloneVar()
|
||||
@@ -34,7 +36,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The type of the value
|
||||
* @return string|null The type of the value
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
@@ -58,10 +60,12 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
if (Stub::TYPE_RESOURCE === $item->type) {
|
||||
return $item->class.' resource';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $recursive Whether values should be resolved recursively or not
|
||||
* @param array|bool $recursive Whether values should be resolved recursively or not
|
||||
*
|
||||
* @return string|int|float|bool|array|Data[]|null A native representation of the original value
|
||||
*/
|
||||
@@ -79,7 +83,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
return $item->value;
|
||||
}
|
||||
|
||||
$children = $item->position ? $this->data[$item->position] : array();
|
||||
$children = $item->position ? $this->data[$item->position] : [];
|
||||
|
||||
foreach ($children as $k => $v) {
|
||||
if ($recursive && !($v = $this->getStub($v)) instanceof Stub) {
|
||||
@@ -104,15 +108,23 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
return $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return \count($this->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Traversable
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
if (!\is_array($value = $this->getValue())) {
|
||||
throw new \LogicException(sprintf('%s object holds non-iterable type "%s".', self::class, \gettype($value)));
|
||||
throw new \LogicException(sprintf('"%s" object holds non-iterable type "%s".', self::class, \gettype($value)));
|
||||
}
|
||||
|
||||
yield from $value;
|
||||
@@ -123,35 +135,59 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
if (null !== $data = $this->seek($key)) {
|
||||
$item = $this->getStub($data->data[$data->position][$data->key]);
|
||||
|
||||
return $item instanceof Stub || array() === $item ? $data : $item;
|
||||
return $item instanceof Stub || [] === $item ? $data : $item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($key)
|
||||
{
|
||||
return null !== $this->seek($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetExists($key)
|
||||
{
|
||||
return $this->__isset($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($key)
|
||||
{
|
||||
return $this->__get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetSet($key, $value)
|
||||
{
|
||||
throw new \BadMethodCallException(self::class.' objects are immutable.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetUnset($key)
|
||||
{
|
||||
throw new \BadMethodCallException(self::class.' objects are immutable.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$value = $this->getValue();
|
||||
@@ -168,7 +204,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
*
|
||||
* @param int $maxDepth The max dumped depth level
|
||||
*
|
||||
* @return self A clone of $this
|
||||
* @return static
|
||||
*/
|
||||
public function withMaxDepth($maxDepth)
|
||||
{
|
||||
@@ -183,7 +219,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
*
|
||||
* @param int $maxItemsPerDepth The max number of items dumped per depth level
|
||||
*
|
||||
* @return self A clone of $this
|
||||
* @return static
|
||||
*/
|
||||
public function withMaxItemsPerDepth($maxItemsPerDepth)
|
||||
{
|
||||
@@ -198,7 +234,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
*
|
||||
* @param bool $useRefHandles False to hide global ref. handles
|
||||
*
|
||||
* @return self A clone of $this
|
||||
* @return static
|
||||
*/
|
||||
public function withRefHandles($useRefHandles)
|
||||
{
|
||||
@@ -208,12 +244,23 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public function withContext(array $context)
|
||||
{
|
||||
$data = clone $this;
|
||||
$data->context = $context;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeks to a specific key in nested data structures.
|
||||
*
|
||||
* @param string|int $key The key to seek to
|
||||
*
|
||||
* @return self|null A clone of $this or null if the key is not set
|
||||
* @return static|null Null if the key is not set
|
||||
*/
|
||||
public function seek($key)
|
||||
{
|
||||
@@ -223,9 +270,9 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
$item = $item->value;
|
||||
}
|
||||
if (!($item = $this->getStub($item)) instanceof Stub || !$item->position) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$keys = array($key);
|
||||
$keys = [$key];
|
||||
|
||||
switch ($item->type) {
|
||||
case Stub::TYPE_OBJECT:
|
||||
@@ -238,14 +285,14 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
case Stub::TYPE_RESOURCE:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = null;
|
||||
$children = $this->data[$item->position];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (isset($children[$key]) || array_key_exists($key, $children)) {
|
||||
if (isset($children[$key]) || \array_key_exists($key, $children)) {
|
||||
$data = clone $this;
|
||||
$data->key = $key;
|
||||
$data->position = $item->position;
|
||||
@@ -261,19 +308,27 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
*/
|
||||
public function dump(DumperInterface $dumper)
|
||||
{
|
||||
$refs = array(0);
|
||||
$this->dumpItem($dumper, new Cursor(), $refs, $this->data[$this->position][$this->key]);
|
||||
$refs = [0];
|
||||
$cursor = new Cursor();
|
||||
|
||||
if ($cursor->attr = $this->context[SourceContextProvider::class] ?? []) {
|
||||
$cursor->attr['if_links'] = true;
|
||||
$cursor->hashType = -1;
|
||||
$dumper->dumpScalar($cursor, 'default', '^');
|
||||
$cursor->attr = ['if_links' => true];
|
||||
$dumper->dumpScalar($cursor, 'default', ' ');
|
||||
$cursor->hashType = 0;
|
||||
}
|
||||
|
||||
$this->dumpItem($dumper, $cursor, $refs, $this->data[$this->position][$this->key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Depth-first dumping of items.
|
||||
*
|
||||
* @param DumperInterface $dumper The dumper being used for dumping
|
||||
* @param Cursor $cursor A cursor used for tracking dumper state position
|
||||
* @param array &$refs A map of all references discovered while dumping
|
||||
* @param mixed $item A Stub object or the original value being dumped
|
||||
* @param mixed $item A Stub object or the original value being dumped
|
||||
*/
|
||||
private function dumpItem($dumper, $cursor, &$refs, $item)
|
||||
private function dumpItem(DumperInterface $dumper, Cursor $cursor, array &$refs, $item)
|
||||
{
|
||||
$cursor->refIndex = 0;
|
||||
$cursor->softRefTo = $cursor->softRefHandle = $cursor->softRefCount = 0;
|
||||
@@ -281,21 +336,21 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
$firstSeen = true;
|
||||
|
||||
if (!$item instanceof Stub) {
|
||||
$cursor->attr = array();
|
||||
$cursor->attr = [];
|
||||
$type = \gettype($item);
|
||||
if ($item && 'array' === $type) {
|
||||
$item = $this->getStub($item);
|
||||
}
|
||||
} elseif (Stub::TYPE_REF === $item->type) {
|
||||
if ($item->handle) {
|
||||
if (!isset($refs[$r = $item->handle - (PHP_INT_MAX >> 1)])) {
|
||||
if (!isset($refs[$r = $item->handle - (\PHP_INT_MAX >> 1)])) {
|
||||
$cursor->refIndex = $refs[$r] = $cursor->refIndex ?: ++$refs[0];
|
||||
} else {
|
||||
$firstSeen = false;
|
||||
}
|
||||
$cursor->hardRefTo = $refs[$r];
|
||||
$cursor->hardRefHandle = $this->useRefHandles & $item->handle;
|
||||
$cursor->hardRefCount = $item->refCount;
|
||||
$cursor->hardRefCount = 0 < $item->handle ? $item->refCount : 0;
|
||||
}
|
||||
$cursor->attr = $item->attr;
|
||||
$type = $item->class ?: \gettype($item->value);
|
||||
@@ -322,10 +377,10 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
if ($cut >= 0) {
|
||||
$cut += \count($children);
|
||||
}
|
||||
$children = array();
|
||||
$children = [];
|
||||
}
|
||||
} else {
|
||||
$children = array();
|
||||
$children = [];
|
||||
}
|
||||
switch ($item->type) {
|
||||
case Stub::TYPE_STRING:
|
||||
@@ -356,7 +411,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \RuntimeException(sprintf('Unexpected Stub type: %s', $item->type));
|
||||
throw new \RuntimeException(sprintf('Unexpected Stub type: "%s".', $item->type));
|
||||
}
|
||||
} elseif ('array' === $type) {
|
||||
$dumper->enterHash($cursor, Cursor::HASH_INDEXED, 0, false);
|
||||
@@ -371,17 +426,9 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
/**
|
||||
* Dumps children of hash structures.
|
||||
*
|
||||
* @param DumperInterface $dumper
|
||||
* @param Cursor $parentCursor The cursor of the parent hash
|
||||
* @param array &$refs A map of all references discovered while dumping
|
||||
* @param array $children The children to dump
|
||||
* @param int $hashCut The number of items removed from the original hash
|
||||
* @param string $hashType A Cursor::HASH_* const
|
||||
* @param bool $dumpKeys Whether keys should be dumped or not
|
||||
*
|
||||
* @return int The final number of removed items
|
||||
*/
|
||||
private function dumpChildren($dumper, $parentCursor, &$refs, $children, $hashCut, $hashType, $dumpKeys)
|
||||
private function dumpChildren(DumperInterface $dumper, Cursor $parentCursor, array &$refs, array $children, int $hashCut, int $hashType, bool $dumpKeys): int
|
||||
{
|
||||
$cursor = clone $parentCursor;
|
||||
++$cursor->depth;
|
||||
|
Reference in New Issue
Block a user