function OptimizedPhpArrayDumper::dumpCollection

Same name in other branches
  1. 9 core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::dumpCollection()
  2. 10 core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::dumpCollection()
  3. 11.x core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::dumpCollection()

Dumps a collection to a PHP array.

Parameters

mixed $collection: A collection to process.

bool &$resolve: Used for passing the information to the caller whether the given collection needed to be resolved or not. This is used for optimizing deep arrays that don't need to be traversed.

Return value

object|array The collection in a suitable format.

2 calls to OptimizedPhpArrayDumper::dumpCollection()
OptimizedPhpArrayDumper::dumpMethodCalls in core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
Dumps method calls to a PHP array.
OptimizedPhpArrayDumper::getServiceDefinition in core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
Gets a service definition as PHP array.
1 method overrides OptimizedPhpArrayDumper::dumpCollection()
PhpArrayDumper::dumpCollection in core/lib/Drupal/Component/DependencyInjection/Dumper/PhpArrayDumper.php
Dumps a collection to a PHP array.

File

core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php, line 306

Class

OptimizedPhpArrayDumper
OptimizedPhpArrayDumper dumps a service container as a serialized PHP array.

Namespace

Drupal\Component\DependencyInjection\Dumper

Code

protected function dumpCollection($collection, &$resolve = FALSE) {
    $code = [];
    foreach ($collection as $key => $value) {
        if (is_array($value)) {
            $resolve_collection = FALSE;
            $code[$key] = $this->dumpCollection($value, $resolve_collection);
            if ($resolve_collection) {
                $resolve = TRUE;
            }
        }
        else {
            $code[$key] = $this->dumpValue($value);
            if (is_object($code[$key])) {
                $resolve = TRUE;
            }
        }
    }
    if (!$resolve) {
        return $collection;
    }
    return (object) [
        'type' => 'collection',
        'value' => $code,
        'resolve' => $resolve,
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.