/** * 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); } return $this->handlers[$type]; }
/** * 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; }
public function test_that_create_returns_exception_instance() { $exception = HandlerNotFoundException::create('Handler not found'); $this->assertInstanceOf('Novuso\\Common\\Application\\Messaging\\Command\\Exception\\HandlerNotFoundException', $exception); }