/** * @param QueryInterface $query * @return $this * @throws \InvalidArgumentException */ public function registerQuery(QueryInterface $query) { $name = $query->getName(); if ($this->hasQuery($name)) { throw new \InvalidArgumentException(sprintf('Query "%s" is already registered!', $name)); } $this->queries[$name] = $query; return $this; }
/** * @param MessageInterface|QueryInterface $message * @return QueryHandlerInterface * @throws QueryBusException */ protected function getHandler(QueryInterface $message) { $messageName = $message->getName(); $handlerId = $this->resolver->resolve($messageName); if (!$this->locator->has($handlerId)) { throw new QueryBusException(sprintf("Cannot instantiate handler '%s' for query '%s'", $handlerId, $messageName)); } /** @var QueryHandlerInterface $handler */ $handler = $this->locator->get($handlerId); if (!$handler instanceof QueryHandlerInterface) { throw new QueryBusException(sprintf("Handler '%s' returned by locator for query '%s' should implement QueryHandlerInterface", $handlerId, $messageName)); } return $handler; }