private function PhpDumper::addServiceInstance in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/dependency-injection/Dumper/PhpDumper.php \Symfony\Component\DependencyInjection\Dumper\PhpDumper::addServiceInstance()
Generates the service instance.
Parameters
string $id:
Definition $definition:
Return value
string
Throws
1 call to PhpDumper::addServiceInstance()
- PhpDumper::addService in vendor/
symfony/ dependency-injection/ Dumper/ PhpDumper.php - Adds a service.
File
- vendor/
symfony/ dependency-injection/ Dumper/ PhpDumper.php, line 367
Class
- PhpDumper
- PhpDumper dumps a service container as a PHP class.
Namespace
Symfony\Component\DependencyInjection\DumperCode
private function addServiceInstance($id, $definition) {
$class = $definition
->getClass();
if ('\\' === substr($class, 0, 1)) {
$class = substr($class, 1);
}
$class = $this
->dumpValue($class);
if (0 === strpos($class, "'") && !preg_match('/^\'[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));
}
$simple = $this
->isSimpleInstance($id, $definition);
$isProxyCandidate = $this
->getProxyDumper()
->isProxyCandidate($definition);
$instantiation = '';
if (!$isProxyCandidate && ContainerInterface::SCOPE_CONTAINER === $definition
->getScope()) {
$instantiation = "\$this->services['{$id}'] = " . ($simple ? '' : '$instance');
}
elseif (!$isProxyCandidate && ContainerInterface::SCOPE_PROTOTYPE !== ($scope = $definition
->getScope())) {
$instantiation = "\$this->services['{$id}'] = \$this->scopedServices['{$scope}']['{$id}'] = " . ($simple ? '' : '$instance');
}
elseif (!$simple) {
$instantiation = '$instance';
}
$return = '';
if ($simple) {
$return = 'return ';
}
else {
$instantiation .= ' = ';
}
$code = $this
->addNewInstance($id, $definition, $return, $instantiation);
if (!$simple) {
$code .= "\n";
}
return $code;
}