function PhpDumper::addInlineReference
2 calls to PhpDumper::addInlineReference()
- PhpDumper::addInlineService in vendor/
symfony/ dependency-injection/ Dumper/ PhpDumper.php - PhpDumper::addInlineVariables in vendor/
symfony/ dependency-injection/ Dumper/ PhpDumper.php
File
-
vendor/
symfony/ dependency-injection/ Dumper/ PhpDumper.php, line 981
Class
- PhpDumper
- PhpDumper dumps a service container as a PHP class.
Namespace
Symfony\Component\DependencyInjection\DumperCode
private function addInlineReference(string $id, Definition $definition, string $targetId, bool $forConstructor) : string {
while ($this->container
->hasAlias($targetId)) {
$targetId = (string) $this->container
->getAlias($targetId);
}
[
$callCount,
$behavior,
] = $this->serviceCalls[$targetId];
if ($id === $targetId) {
return $this->addInlineService($id, $definition, $definition);
}
if ('service_container' === $targetId || isset($this->referenceVariables[$targetId])) {
return '';
}
if ($this->container
->hasDefinition($targetId) && ($def = $this->container
->getDefinition($targetId)) && !$def->isShared()) {
return '';
}
$hasSelfRef = isset($this->circularReferences[$id][$targetId]) && !isset($this->definitionVariables[$definition]) && !($this->hasProxyDumper && $definition->isLazy());
if ($hasSelfRef && !$forConstructor && !($forConstructor = !$this->circularReferences[$id][$targetId])) {
$code = $this->addInlineService($id, $definition, $definition);
}
else {
$code = '';
}
if (isset($this->referenceVariables[$targetId]) || 2 > $callCount && (!$hasSelfRef || !$forConstructor)) {
return $code;
}
$name = $this->getNextVariableName();
$this->referenceVariables[$targetId] = new Variable($name);
$reference = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $behavior ? new Reference($targetId, $behavior) : null;
$code .= \sprintf(" \$%s = %s;\n", $name, $this->getServiceCall($targetId, $reference));
if (!$hasSelfRef || !$forConstructor) {
return $code;
}
return $code . \sprintf(<<<'EOTXT'
if (isset($container->%s[%s])) {
return $container->%1$s[%2$s];
}
EOTXT
, $this->container
->getDefinition($id)
->isPublic() ? 'services' : 'privates', $this->doExport($id));
}