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

Breadcrumb

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

function AbstractCloner::castObject

Casts an object to an array representation.

Parameters

bool $isNested True if the object is nested in the dumped structure:

1 call to AbstractCloner::castObject()
VarCloner::doClone in vendor/symfony/var-dumper/Cloner/VarCloner.php
Effectively clones the PHP variable.

File

vendor/symfony/var-dumper/Cloner/AbstractCloner.php, line 331

Class

AbstractCloner
AbstractCloner implements a generic caster mechanism for objects and resources.

Namespace

Symfony\Component\VarDumper\Cloner

Code

protected function castObject(Stub $stub, bool $isNested) : array {
    $obj = $stub->value;
    $class = $stub->class;
    if (str_contains($class, "@anonymous\x00")) {
        $stub->class = get_debug_type($obj);
    }
    if (isset($this->classInfo[$class])) {
        [
            $i,
            $parents,
            $hasDebugInfo,
            $fileInfo,
        ] = $this->classInfo[$class];
    }
    else {
        $i = 2;
        $parents = [
            $class,
        ];
        $hasDebugInfo = method_exists($class, '__debugInfo');
        foreach (class_parents($class) as $p) {
            $parents[] = $p;
            ++$i;
        }
        foreach (class_implements($class) as $p) {
            $parents[] = $p;
            ++$i;
        }
        $parents[] = '*';
        $r = new \ReflectionClass($class);
        $fileInfo = $r->isInternal() || $r->isSubclassOf(Stub::class) ? [] : [
            'file' => $r->getFileName(),
            'line' => $r->getStartLine(),
        ];
        $this->classInfo[$class] = [
            $i,
            $parents,
            $hasDebugInfo,
            $fileInfo,
        ];
    }
    $stub->attr += $fileInfo;
    $a = Caster::castObject($obj, $class, $hasDebugInfo, $stub->class);
    try {
        while ($i--) {
            if (!empty($this->casters[$p = $parents[$i]])) {
                foreach ($this->casters[$p] as $callback) {
                    $a = $callback($obj, $a, $stub, $isNested, $this->filter);
                }
            }
        }
    } catch (\Exception $e) {
        $a = [
            (Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '') . '⚠' => new ThrowingCasterException($e),
        ] + $a;
    }
    return $a;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal