function Container::set
Same name in this branch
- 11.1.x core/lib/Drupal/Component/DependencyInjection/Container.php \Drupal\Component\DependencyInjection\Container::set()
Sets a service.
Setting a synthetic service to null resets it: has() returns false and get() behaves in the same way as if the service was never created.
Overrides ContainerInterface::set
4 calls to Container::set()
- Container::getEnv in vendor/
symfony/ dependency-injection/ Container.php - Fetches a variable from the environment.
- ContainerBuilder::set in core/
lib/ Drupal/ Core/ DependencyInjection/ ContainerBuilder.php - Overrides Symfony\Component\DependencyInjection\ContainerBuilder::set().
- ContainerBuilder::set in vendor/
symfony/ dependency-injection/ ContainerBuilder.php - Sets a service.
- ContainerBuilder::set in vendor/
symfony/ dependency-injection/ ContainerBuilder.php - Sets a service.
1 method overrides Container::set()
- ContainerBuilder::set in vendor/
symfony/ dependency-injection/ ContainerBuilder.php - Sets a service.
File
-
vendor/
symfony/ dependency-injection/ Container.php, line 138
Class
- Container
- Container is a dependency injection container.
Namespace
Symfony\Component\DependencyInjectionCode
public function set(string $id, ?object $service) : void {
// Runs the internal initializer; used by the dumped container to include always-needed files
if (isset($this->privates['service_container']) && $this->privates['service_container'] instanceof \Closure) {
$initialize = $this->privates['service_container'];
unset($this->privates['service_container']);
$initialize($this);
}
if ('service_container' === $id) {
throw new InvalidArgumentException('You cannot set service "service_container".');
}
if (!(isset($this->fileMap[$id]) || isset($this->methodMap[$id]))) {
if (isset($this->syntheticIds[$id]) || !isset($this->getRemovedIds()[$id])) {
// no-op
}
elseif (null === $service) {
throw new InvalidArgumentException(\sprintf('The "%s" service is private, you cannot unset it.', $id));
}
else {
throw new InvalidArgumentException(\sprintf('The "%s" service is private, you cannot replace it.', $id));
}
}
elseif (isset($this->services[$id])) {
throw new InvalidArgumentException(\sprintf('The "%s" service is already initialized, you cannot replace it.', $id));
}
if (isset($this->aliases[$id])) {
unset($this->aliases[$id]);
}
if (null === $service) {
unset($this->services[$id]);
return;
}
$this->services[$id] = $service;
}