You are here

protected function OptimizedPhpArrayDumper::getServiceDefinition 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::getServiceDefinition()

Gets a service definition as PHP array.

Parameters

\Symfony\Component\DependencyInjection\Definition $definition: The definition to process.

Return value

array The service definition as PHP array.

Throws

\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException Thrown when the definition is marked as decorated, or with an explicit scope different from SCOPE_CONTAINER and SCOPE_PROTOTYPE.

2 calls to OptimizedPhpArrayDumper::getServiceDefinition()
OptimizedPhpArrayDumper::getPrivateServiceCall in core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
Gets a private service definition in a suitable format.
OptimizedPhpArrayDumper::getServiceDefinitions in core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
Gets services of the container as a PHP array.

File

core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php, line 204
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 getServiceDefinition(Definition $definition) {
  $service = array();
  if ($definition
    ->getClass()) {
    $service['class'] = $definition
      ->getClass();
  }
  if (!$definition
    ->isPublic()) {
    $service['public'] = FALSE;
  }
  if ($definition
    ->getFile()) {
    $service['file'] = $definition
      ->getFile();
  }
  if ($definition
    ->isSynthetic()) {
    $service['synthetic'] = TRUE;
  }
  if ($definition
    ->isLazy()) {
    $service['lazy'] = TRUE;
  }
  if ($definition
    ->getArguments()) {
    $arguments = $definition
      ->getArguments();
    $service['arguments'] = $this
      ->dumpCollection($arguments);
    $service['arguments_count'] = count($arguments);
  }
  else {
    $service['arguments_count'] = 0;
  }
  if ($definition
    ->getProperties()) {
    $service['properties'] = $this
      ->dumpCollection($definition
      ->getProperties());
  }
  if ($definition
    ->getMethodCalls()) {
    $service['calls'] = $this
      ->dumpMethodCalls($definition
      ->getMethodCalls());
  }
  if (($scope = $definition
    ->getScope()) !== ContainerInterface::SCOPE_CONTAINER) {
    if ($scope === ContainerInterface::SCOPE_PROTOTYPE) {

      // Scope prototype has been replaced with 'shared' => FALSE.
      // This is a Symfony 2.8 forward compatibility fix.
      // Reference: https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md#dependencyinjection
      $service['shared'] = FALSE;
    }
    else {
      throw new InvalidArgumentException("The 'scope' definition is deprecated in Symfony 3.0 and not supported by Drupal 8.");
    }
  }
  if (($decorated = $definition
    ->getDecoratedService()) !== NULL) {
    throw new InvalidArgumentException("The 'decorated' definition is not supported by the Drupal 8 run-time container. The Container Builder should have resolved that during the DecoratorServicePass compiler pass.");
  }
  if ($callable = $definition
    ->getFactory()) {
    $service['factory'] = $this
      ->dumpCallable($callable);
  }
  if ($callable = $definition
    ->getConfigurator()) {
    $service['configurator'] = $this
      ->dumpCallable($callable);
  }
  return $service;
}