function PhpDumper::addServiceInstance
Throws
1 call to PhpDumper::addServiceInstance()
- PhpDumper::addInlineService in vendor/
symfony/ dependency-injection/ Dumper/ PhpDumper.php
File
-
vendor/
symfony/ dependency-injection/ Dumper/ PhpDumper.php, line 676
Class
- PhpDumper
- PhpDumper dumps a service container as a PHP class.
Namespace
Symfony\Component\DependencyInjection\DumperCode
private function addServiceInstance(string $id, Definition $definition, bool $isSimpleInstance) : string {
$class = $this->dumpValue($definition->getClass());
if (str_starts_with($class, "'") && !str_contains($class, '$') && !preg_match('/^\'(?:\\\\{2})?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?:\\\\{2}[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*\'$/', $class)) {
throw new InvalidArgumentException(\sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
}
$asGhostObject = false;
$isProxyCandidate = $this->isProxyCandidate($definition, $asGhostObject, $id);
$instantiation = '';
$lastWitherIndex = null;
foreach ($definition->getMethodCalls() as $k => $call) {
if ($call[2] ?? false) {
$lastWitherIndex = $k;
}
}
if (!$isProxyCandidate && $definition->isShared() && !isset($this->singleUsePrivateIds[$id]) && null === $lastWitherIndex) {
$instantiation = \sprintf('$container->%s[%s] = %s', $this->container
->getDefinition($id)
->isPublic() ? 'services' : 'privates', $this->doExport($id), $isSimpleInstance ? '' : '$instance');
}
elseif (!$isSimpleInstance) {
$instantiation = '$instance';
}
$return = '';
if ($isSimpleInstance) {
$return = 'return ';
}
else {
$instantiation .= ' = ';
}
return $this->addNewInstance($definition, ' ' . $return . $instantiation, $id, $asGhostObject);
}