Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Data.php

function Data::dumpItem

Depth-first dumping of items.

Parameters

mixed $item A Stub object or the original value being dumped:

2 calls to Data::dumpItem()
Data::dump in vendor/symfony/var-dumper/Cloner/Data.php
Dumps data with a DumperInterface dumper.
Data::dumpChildren in vendor/symfony/var-dumper/Cloner/Data.php
Dumps children of hash structures.

File

vendor/symfony/var-dumper/Cloner/Data.php, line 286

Class

Data
@author Nicolas Grekas <p@tchwork.com>

Namespace

Symfony\Component\VarDumper\Cloner

Code

private function dumpItem(DumperInterface $dumper, Cursor $cursor, array &$refs, mixed $item) : void {
    $cursor->refIndex = 0;
    $cursor->softRefTo = $cursor->softRefHandle = $cursor->softRefCount = 0;
    $cursor->hardRefTo = $cursor->hardRefHandle = $cursor->hardRefCount = 0;
    $firstSeen = true;
    if (!$item instanceof Stub) {
        $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)])) {
                $cursor->refIndex = $refs[$r] = $cursor->refIndex ?: ++$refs[0];
            }
            else {
                $firstSeen = false;
            }
            $cursor->hardRefTo = $refs[$r];
            $cursor->hardRefHandle = $this->useRefHandles & $item->handle;
            $cursor->hardRefCount = 0 < $item->handle ? $item->refCount : 0;
        }
        $cursor->attr = $item->attr;
        $type = $item->class ?: \gettype($item->value);
        $item = $this->getStub($item->value);
    }
    if ($item instanceof Stub) {
        if ($item->refCount) {
            if (!isset($refs[$r = $item->handle])) {
                $cursor->refIndex = $refs[$r] = $cursor->refIndex ?: ++$refs[0];
            }
            else {
                $firstSeen = false;
            }
            $cursor->softRefTo = $refs[$r];
        }
        $cursor->softRefHandle = $this->useRefHandles & $item->handle;
        $cursor->softRefCount = $item->refCount;
        $cursor->attr = $item->attr;
        $cut = $item->cut;
        if ($item->position && $firstSeen) {
            $children = $this->data[$item->position];
            if ($cursor->stop) {
                if ($cut >= 0) {
                    $cut += \count($children);
                }
                $children = [];
            }
        }
        else {
            $children = [];
        }
        switch ($item->type) {
            case Stub::TYPE_STRING:
                $dumper->dumpString($cursor, $item->value, Stub::STRING_BINARY === $item->class, $cut);
                break;
            case Stub::TYPE_ARRAY:
                $item = clone $item;
                $item->type = $item->class;
                $item->class = $item->value;
            // no break
            case Stub::TYPE_OBJECT:
            case Stub::TYPE_RESOURCE:
                $withChildren = $children && $cursor->depth !== $this->maxDepth && $this->maxItemsPerDepth;
                $dumper->enterHash($cursor, $item->type, $item->class, $withChildren);
                if ($withChildren) {
                    if ($cursor->skipChildren) {
                        $withChildren = false;
                        $cut = -1;
                    }
                    else {
                        $cut = $this->dumpChildren($dumper, $cursor, $refs, $children, $cut, $item->type, null !== $item->class);
                    }
                }
                elseif ($children && 0 <= $cut) {
                    $cut += \count($children);
                }
                $cursor->skipChildren = false;
                $dumper->leaveHash($cursor, $item->type, $item->class, $withChildren, $cut);
                break;
            case Stub::TYPE_SCALAR:
                $dumper->dumpScalar($cursor, 'default', $item->attr['value']);
                break;
            default:
                throw new \RuntimeException(\sprintf('Unexpected Stub type: "%s".', $item->type));
        }
    }
    elseif ('array' === $type) {
        $dumper->enterHash($cursor, Cursor::HASH_INDEXED, 0, false);
        $dumper->leaveHash($cursor, Cursor::HASH_INDEXED, 0, false, 0);
    }
    elseif ('string' === $type) {
        $dumper->dumpString($cursor, $item, false, 0);
    }
    else {
        $dumper->dumpScalar($cursor, $type, $item);
    }
}
RSS feed
Powered by Drupal