function OptimizedPhpArrayDumper::getReferenceCall

Same name in other branches
  1. 9 core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::getReferenceCall()
  2. 8.9.x core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::getReferenceCall()
  3. 11.x core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::getReferenceCall()

Gets a service reference for a reference in a suitable PHP array format.

The main difference is that this function treats references to private services differently and returns a private service reference instead of a normal reference.

Parameters

string $id: The ID of the service to get a reference for.

\Symfony\Component\DependencyInjection\Reference|null $reference: (optional) The reference object to process; needed to get the invalid behavior value.

Return value

string|object A suitable representation of the service reference.

1 call to OptimizedPhpArrayDumper::getReferenceCall()
OptimizedPhpArrayDumper::dumpValue in core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
Dumps the value to PHP array format.

File

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

Class

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

Namespace

Drupal\Component\DependencyInjection\Dumper

Code

protected function getReferenceCall($id, ?Reference $reference = NULL) {
    $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
    if ($reference !== NULL) {
        $invalid_behavior = $reference->getInvalidBehavior();
    }
    // Private shared service.
    if (isset($this->aliases[$id])) {
        $id = $this->aliases[$id];
    }
    $definition = $this->container
        ->getDefinition($id);
    if (!$definition->isPublic()) {
        // The ContainerBuilder does not share a private service, but this means a
        // new service is instantiated every time. Use a private shared service to
        // circumvent the problem.
        return $this->getPrivateServiceCall($id, $definition, TRUE);
    }
    return $this->getServiceCall($id, $invalid_behavior);
}

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