You are here

private function PhpDumper::addServiceInlinedDefinitionsSetup 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::addServiceInlinedDefinitionsSetup()

Generates the inline definition setup.

Parameters

string $id:

Definition $definition:

Return value

string

Throws

ServiceCircularReferenceException when the container contains a circular reference

1 call to PhpDumper::addServiceInlinedDefinitionsSetup()
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 476

Class

PhpDumper
PhpDumper dumps a service container as a PHP class.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

private function addServiceInlinedDefinitionsSetup($id, $definition) {
  $this->referenceVariables[$id] = new Variable('instance');
  $code = '';
  $processed = new \SplObjectStorage();
  foreach ($this
    ->getInlinedDefinitions($definition) as $iDefinition) {
    if ($processed
      ->contains($iDefinition)) {
      continue;
    }
    $processed
      ->offsetSet($iDefinition);
    if (!$this
      ->hasReference($id, $iDefinition
      ->getMethodCalls(), true) && !$this
      ->hasReference($id, $iDefinition
      ->getProperties(), true)) {
      continue;
    }

    // if the instance is simple, the return statement has already been generated
    // so, the only possible way to get there is because of a circular reference
    if ($this
      ->isSimpleInstance($id, $definition)) {
      throw new ServiceCircularReferenceException($id, array(
        $id,
      ));
    }
    $name = (string) $this->definitionVariables
      ->offsetGet($iDefinition);
    $code .= $this
      ->addServiceMethodCalls(null, $iDefinition, $name);
    $code .= $this
      ->addServiceProperties(null, $iDefinition, $name);
    $code .= $this
      ->addServiceConfigurator(null, $iDefinition, $name);
  }
  if ('' !== $code) {
    $code .= "\n";
  }
  return $code;
}