OptimizedPhpArrayDumper::getServiceDefinition

protected OptimizedPhpArrayDumper::getServiceDefinition(Definition $definition)

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.

File

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

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.");
    }
  }

  // By default services are shared, so just provide the flag, when needed.
  if ($definition->isShared() === FALSE) {
    $service['shared'] = $definition->isShared();
  }

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

Please login to continue.