/** * Retrieves a responder by action class name * * @param string $actionClass The full action class name * * @return Responder * * @throws LogicException When the handler is not found */ public function getResponder($actionClass) { $type = Type::create($actionClass)->toString(); if (!isset($this->responders[$type])) { $message = sprintf('Responder not defined for action: %s', $actionClass); throw new LogicException($message); } $serviceId = $this->responders[$type]; try { $responder = $this->container->get($serviceId); } catch (ServiceContainerException $exception) { throw new LogicException($exception->getMessage(), $exception->getCode(), $exception); } return $responder; }
/** * Retrieves a handler by command class name * * @param string $commandClass The full command class name * * @return CommandHandler * * @throws HandlerNotFoundException When the handler is not found */ public function getHandler($commandClass) { $type = Type::create($commandClass)->toString(); if (!isset($this->handlers[$type])) { $message = sprintf('Handler not defined for command: %s', $commandClass); throw HandlerNotFoundException::create($message); } $serviceId = $this->handlers[$type]; try { $handler = $this->container->get($serviceId); } catch (ServiceContainerException $exception) { throw HandlerNotFoundException::create($exception->getMessage(), $exception); } return $handler; }
/** * Lazy loads event handlers from the service container * * @param string $eventType The event type * * @return void */ protected function lazyLoad($eventType) { if (isset($this->serviceIds[$eventType])) { foreach ($this->serviceIds[$eventType] as $args) { list($serviceId, $method, $priority) = $args; $service = $this->container->get($serviceId); $key = $serviceId . '.' . $method; if (!isset($this->services[$eventType][$key])) { $this->addHandler($eventType, [$service, $method], $priority); } elseif ($service !== $this->services[$eventType][$key]) { parent::removeHandler($eventType, [$this->services[$eventType][$key], $method]); $this->addHandler($eventType, [$service, $method], $priority); } $this->services[$eventType][$key] = $service; } } }