Gets a service.
@api
string $id The service identifier:
integer $invalidBehavior The behavior when the service does not exist:
object The associated service
InvalidArgumentException if the service is not defined
LogicException if the service has a circular reference to itself
Overrides Container::get
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;
}
}