public function ContainerBuilder::get in Service Container 7.2
Same name and namespace in other branches
- 7 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/ContainerBuilder.php \Symfony\Component\DependencyInjection\ContainerBuilder::get()
Gets a service.
@api
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
See also
4 calls to ContainerBuilder::get()
- ContainerBuilder::createService in modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ ContainerBuilder.php - Creates a service for a service definition.
- ContainerBuilder::resolveServices in modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ ContainerBuilder.php - Replaces service references by the real service instance and evaluates expressions.
- ContainerBuilder::synchronize in lib/
Drupal/ Core/ DependencyInjection/ ContainerBuilder.php - Synchronizes a service change.
- ContainerBuilder::synchronize in modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ ContainerBuilder.php - Synchronizes a service change.
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ ContainerBuilder.php, line 465
Class
- ContainerBuilder
- ContainerBuilder is a DI container that provides an API to easily describe services.
Namespace
Symfony\Component\DependencyInjectionCode
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;
}