private function PhpDumper::addServiceLocalTempVariables

Generates Service local temp variables.

Parameters

string $cId:

string $definition:

Return value

string

1 call to PhpDumper::addServiceLocalTempVariables()
PhpDumper::addService in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Adds a service

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php, line 143

Class

PhpDumper
PhpDumper dumps a service container as a PHP class.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

private function addServiceLocalTempVariables($cId, $definition) {
  static $template = "        \$%s = %s;\n";
  $localDefinitions = array_merge(array(
    $definition,
  ), $this
    ->getInlinedDefinitions($definition));
  $calls = $behavior = array();
  foreach ($localDefinitions as $iDefinition) {
    $this
      ->getServiceCallsFromArguments($iDefinition
      ->getArguments(), $calls, $behavior);
    $this
      ->getServiceCallsFromArguments($iDefinition
      ->getMethodCalls(), $calls, $behavior);
    $this
      ->getServiceCallsFromArguments($iDefinition
      ->getProperties(), $calls, $behavior);
  }
  $code = '';
  foreach ($calls as $id => $callCount) {
    if ('service_container' === $id || $id === $cId) {
      continue;
    }
    if ($callCount > 1) {
      $name = $this
        ->getNextVariableName();
      $this->referenceVariables[$id] = new Variable($name);
      if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $behavior[$id]) {
        $code .= sprintf($template, $name, $this
          ->getServiceCall($id));
      }
      else {
        $code .= sprintf($template, $name, $this
          ->getServiceCall($id, new Reference($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)));
      }
    }
  }
  if ('' !== $code) {
    $code .= "\n";
  }
  return $code;
}