public function Container::loadService in Little helpers 7.2
Load a (possibly cached) service by name.
Parameters
string $name: Name of the service to load.
bool $exception: Whether to throw an exception if the service can’t be loaded. If FALSE then a boolean FALSE will be returned instead.
File
- src/
Services/ Container.php, line 73
Class
- Container
- Dependency injection container.
Namespace
Drupal\little_helpers\ServicesCode
public function loadService(string $name, bool $exception = TRUE) {
if ($service = $this->instances[$name] ?? NULL) {
return $service;
}
if ($spec = $this
->getSpec($name, $exception)) {
return $this->instances[$name] = $spec
->instantiate();
}
return FALSE;
}