You are here

protected function OptimizedPhpArrayDumper::getReferenceCall in Service Container 7.2

Same name and namespace in other branches
  1. 7 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|\stdClass A suitable representation of the service reference.

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

File

lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php, line 449
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 getReferenceCall($id, Reference $reference = NULL) {
  $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
  if ($reference !== NULL) {
    $invalid_behavior = $reference
      ->getInvalidBehavior();
  }

  // Private shared service.
  $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);
}