public function ContainerBuilder::get

Gets a service.

@api

Parameters

string $id The service identifier:

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

Return value

object The associated service

Throws

InvalidArgumentException if the service is not defined

LogicException if the service has a circular reference to itself

Overrides Container::get

See also

Reference

2 calls to ContainerBuilder::get()
ContainerBuilder::createService in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php
Creates a service for a service definition.
ContainerBuilder::resolveServices in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php
Replaces service references by the real service instance.

File

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

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);
  try {
    return parent::get($id, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
  } catch (InvalidArgumentException $e) {
    if (isset($this->loading[$id])) {
      throw new LogicException(sprintf('The service "%s" has a circular reference to itself.', $id), 0, $e);
    }
    if (!$this
      ->hasDefinition($id) && isset($this->aliases[$id])) {
      return $this
        ->get($this->aliases[$id]);
    }
    try {
      $definition = $this
        ->getDefinition($id);
    } catch (InvalidArgumentException $e) {
      if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
        return null;
      }
      throw $e;
    }
    $this->loading[$id] = true;
    $service = $this
      ->createService($definition, $id);
    unset($this->loading[$id]);
    return $service;
  }
}