/** * Gets a service. * * @param string $id The service identifier * * @return object The associated service * * @throw InvalidArgumentException if the service is not defined * @throw LogicException if the service has a circular reference to itself */ public function getService($id) { try { return parent::getService($id); } catch (InvalidArgumentException $e) { if (isset($this->loading[$id])) { throw new LogicException(sprintf('The service "%s" has a circular reference to itself.', $id)); } if (!$this->hasServiceDefinition($id) && isset($this->aliases[$id])) { return $this->getService($this->aliases[$id]); } $definition = $this->getServiceDefinition($id); $this->loading[$id] = true; if ($definition->isShared()) { $service = $this->services[$id] = $this->createService($definition); } else { $service = $this->createService($definition); } unset($this->loading[$id]); return $service; } }