You are here

private function PhpDumper::addServiceLocalTempVariables in Service Container 7

Same name and namespace in other branches
  1. 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php \Symfony\Component\DependencyInjection\Dumper\PhpDumper::addServiceLocalTempVariables()

Generates Service local temp variables.

Parameters

string $cId:

string $definition:

Return value

string

1 call to PhpDumper::addServiceLocalTempVariables()
PhpDumper::addService in modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Adds a service.

File

modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php, line 186

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);
    $this
      ->getServiceCallsFromArguments(array(
      $iDefinition
        ->getConfigurator(),
    ), $calls, $behavior);
    $this
      ->getServiceCallsFromArguments(array(
      $iDefinition
        ->getFactory(),
    ), $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;
}