OptimizedPhpArrayDumper::dumpValue

protected OptimizedPhpArrayDumper::dumpValue($value)

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.

File

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

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;
}
doc_Drupal
2016-10-29 09:32:36
Comments
Leave a Comment

Please login to continue.