Generates the service instance.
string $id:
Definition $definition:
string
private function addServiceInstance($id, $definition) {
$class = $this
->dumpValue($definition
->getClass());
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;
}