You are here

public function ContainerBuilder::get in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/dependency-injection/ContainerBuilder.php \Symfony\Component\DependencyInjection\ContainerBuilder::get()

Gets a service.

Parameters

string $id The service identifier:

int $invalidBehavior The behavior when the service does not exist:

Return value

object The associated service

Throws

InvalidArgumentException when no definitions are available

InactiveScopeException when the current scope is not active

LogicException when a circular dependency is detected

\Exception

Overrides ContainerInterface::get

See also

Reference

3 calls to ContainerBuilder::get()
ContainerBuilder::createService in vendor/symfony/dependency-injection/ContainerBuilder.php
Creates a service for a service definition.
ContainerBuilder::resolveServices in vendor/symfony/dependency-injection/ContainerBuilder.php
Replaces service references by the real service instance and evaluates expressions.
ContainerBuilder::synchronize in vendor/symfony/dependency-injection/ContainerBuilder.php
Synchronizes a service change.

File

vendor/symfony/dependency-injection/ContainerBuilder.php, line 427

Class

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

Namespace

Symfony\Component\DependencyInjection

Code

public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
  $id = strtolower($id);
  if ($service = parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
    return $service;
  }
  if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
    return $this
      ->get($this->aliasDefinitions[$id]);
  }
  try {
    $definition = $this
      ->getDefinition($id);
  } catch (InvalidArgumentException $e) {
    if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
      return;
    }
    throw $e;
  }
  $this->loading[$id] = true;
  try {
    $service = $this
      ->createService($definition, $id);
  } catch (\Exception $e) {
    unset($this->loading[$id]);
    if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
      return;
    }
    throw $e;
  }
  unset($this->loading[$id]);
  return $service;
}