You are here

public function ContainerBuilder::register in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php \Drupal\Core\DependencyInjection\ContainerBuilder::register()

File

core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php, line 89

Class

ContainerBuilder
Drupal's dependency injection container builder.

Namespace

Drupal\Core\DependencyInjection

Code

public function register($id, $class = null) {
  if (strtolower($id) !== $id) {
    throw new \InvalidArgumentException("Service ID names must be lowercase: {$id}");
  }
  $definition = new Definition($class);

  // As of Symfony 5.2 all services are private by default, but in Drupal
  // services are still public by default.
  $definition
    ->setPublic(TRUE);
  return $this
    ->setDefinition($id, $definition);
}