public function ContainerBuilder::setAlias

Sets an alias for an existing service.

@api

Parameters

string $alias The alias to create:

string|Alias $id The service to alias:

Throws

InvalidArgumentException if the id is not a string or an Alias

InvalidArgumentException if the alias is for itself

1 call to ContainerBuilder::setAlias()
ContainerBuilder::addAliases in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php
Adds the service aliases.

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php, line 684

Class

ContainerBuilder
ContainerBuilder is a DI container that provides an API to easily describe services.

Namespace

Symfony\Component\DependencyInjection

Code

public function setAlias($alias, $id) {
  $alias = strtolower($alias);
  if (is_string($id)) {
    $id = new Alias($id);
  }
  elseif (!$id instanceof Alias) {
    throw new InvalidArgumentException('$id must be a string, or an Alias object.');
  }
  if ($alias === strtolower($id)) {
    throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias));
  }
  unset($this->definitions[$alias]);
  $this->aliasDefinitions[$alias] = $id;
}