function OptimizedPhpArrayDumper::getServiceDefinition

Same name in other branches
  1. 9 core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::getServiceDefinition()
  2. 10 core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::getServiceDefinition()
  3. 11.x 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 209

Class

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

Namespace

Drupal\Component\DependencyInjection\Dumper

Code

protected function getServiceDefinition(Definition $definition) {
    $service = [];
    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());
    }
    // 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;
}

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