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

Breadcrumb

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

function Snapshot::enumerateObjectsAndResources

1 call to Snapshot::enumerateObjectsAndResources()
Snapshot::canBeSerialized in vendor/sebastian/global-state/src/Snapshot.php

File

vendor/sebastian/global-state/src/Snapshot.php, line 312

Class

Snapshot
A snapshot of global state.

Namespace

SebastianBergmann\GlobalState

Code

private function enumerateObjectsAndResources(mixed $variable) : array {
    if (isset(func_get_args()[1])) {
        $processed = func_get_args()[1];
    }
    else {
        $processed = new Context();
    }
    assert($processed instanceof Context);
    $result = [];
    if ($processed->contains($variable)) {
        return $result;
    }
    $array = $variable;
    
    /* @noinspection UnusedFunctionResultInspection */
    $processed->add($variable);
    if (is_array($variable)) {
        foreach ($array as $element) {
            if (!is_array($element) && !is_object($element) && !is_resource($element)) {
                continue;
            }
            if (!is_resource($element)) {
                
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $result = array_merge($result, $this->enumerateObjectsAndResources($element, $processed));
            }
            else {
                $result[] = $element;
            }
        }
    }
    else {
        $result[] = $variable;
        foreach ((new ObjectReflector())->getProperties($variable) as $value) {
            if (!is_array($value) && !is_object($value) && !is_resource($value)) {
                continue;
            }
            if (!is_resource($value)) {
                
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $result = array_merge($result, $this->enumerateObjectsAndResources($value, $processed));
            }
            else {
                $result[] = $value;
            }
        }
    }
    return $result;
}
RSS feed
Powered by Drupal