You are here

public function ContainerBuilder::setAlias in Service Container 7

Same name and namespace in other branches
  1. 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/ContainerBuilder.php \Symfony\Component\DependencyInjection\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 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/ContainerBuilder.php
Adds the service aliases.

File

modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/ContainerBuilder.php, line 677

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 === (string) $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;
}