You are here

protected function OptimizedPhpArrayDumper::dumpValue in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::dumpValue()

Dumps the value to PHP array format.

Parameters

mixed $value: The value to dump.

Return value

mixed The dumped value in a suitable format.

Throws

RuntimeException When trying to dump object or resource.

4 calls to OptimizedPhpArrayDumper::dumpValue()
OptimizedPhpArrayDumper::dumpCallable in core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
Dumps callable to a PHP array.
OptimizedPhpArrayDumper::dumpCollection in core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
Dumps a collection to a PHP array.
OptimizedPhpArrayDumper::prepareParameters in core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
Prepares parameters for the PHP array dumping.
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 398
Contains \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper.

Class

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

Namespace

Drupal\Component\DependencyInjection\Dumper

Code

protected function dumpValue($value) {
  if (is_array($value)) {
    $code = array();
    foreach ($value as $k => $v) {
      $code[$k] = $this
        ->dumpValue($v);
    }
    return $code;
  }
  elseif ($value instanceof Reference) {
    return $this
      ->getReferenceCall((string) $value, $value);
  }
  elseif ($value instanceof Definition) {
    return $this
      ->getPrivateServiceCall(NULL, $value);
  }
  elseif ($value instanceof Parameter) {
    return $this
      ->getParameterCall((string) $value);
  }
  elseif ($value instanceof Expression) {
    throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
  }
  elseif (is_object($value)) {

    // Drupal specific: Instantiated objects have a _serviceId parameter.
    if (isset($value->_serviceId)) {
      return $this
        ->getReferenceCall($value->_serviceId);
    }
    throw new RuntimeException('Unable to dump a service container if a parameter is an object without _serviceId.');
  }
  elseif (is_resource($value)) {
    throw new RuntimeException('Unable to dump a service container if a parameter is a resource.');
  }
  return $value;
}