/** * Gets a service. * * @param string $id The service identifier * * @return object The associated service, or null if not defined. * * @throws RuntimeException If there was a problem retrieving the service. * * @api * @since 3.1.0 */ public function get($id) { if (!$this->_delegate->has($id)) { return null; } try { return $this->_delegate->get($id); } catch (Exception $e) { throw new RuntimeException($e->getMessage()); } }
/** * Gets a service. * * @param string $id The service identifier * @param int $invalidBehavior The behavior when the service does not exist * * @return object The associated service * * @throws ehough_iconic_exception_InvalidArgumentException when no definitions are available * @throws eough_iconic_exception_InactiveScopeException when the current scope is not active * @throws ehough_iconic_exception_LogicException when a circular dependency is detected * @throws Exception * * @see ehough_iconic_Reference * * @api */ public function get($id, $invalidBehavior = ehough_iconic_ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { $id = strtolower($id); if ($service = parent::get($id, ehough_iconic_ContainerInterface::NULL_ON_INVALID_REFERENCE)) { return $service; } if (isset($this->loading[$id])) { throw new ehough_iconic_exception_LogicException(sprintf('The service "%s" has a circular reference to itself.', $id)); } if (!$this->hasDefinition($id) && isset($this->aliasDefinitions[$id])) { return $this->get($this->aliasDefinitions[$id]); } try { $definition = $this->getDefinition($id); } catch (ehough_iconic_exception_InvalidArgumentException $e) { if (ehough_iconic_ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) { return null; } throw $e; } $this->loading[$id] = true; try { $service = $this->createService($definition, $id); } catch (Exception $e) { unset($this->loading[$id]); if ($e instanceof ehough_iconic_exception_InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) { return null; } throw $e; } unset($this->loading[$id]); return $service; }