@@ -20,31 +20,31 @@ |
||
| 20 | 20 | |
| 21 | 21 | class ContainerHandlerProvider implements HandlerProvider |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @param array<string, string> $handlers |
|
| 25 | - * Where _key_ is a message class and _value_ the service identifier of its handler. |
|
| 26 | - */ |
|
| 27 | - public function __construct( |
|
| 28 | - private ContainerInterface $container, |
|
| 29 | - private array $handlers |
|
| 30 | - ) { |
|
| 31 | - $this->container = $container; |
|
| 32 | - $this->handlers = $handlers; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function getHandlerForMessage(object $message): callable |
|
| 36 | - { |
|
| 37 | - $class = get_class($message); |
|
| 38 | - $id = $this->handlers[$class] ?? null; |
|
| 39 | - |
|
| 40 | - if (!$id) { |
|
| 41 | - throw new NotFound("No handler for messages of type `$class`."); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - try { |
|
| 45 | - return $this->container->get($id); // @phpstan-ignore-line |
|
| 46 | - } catch (NotFoundExceptionInterface $e) { |
|
| 47 | - throw new NotFound("No handler for messages of type `$class`.", $e); |
|
| 48 | - } |
|
| 49 | - } |
|
| 23 | + /** |
|
| 24 | + * @param array<string, string> $handlers |
|
| 25 | + * Where _key_ is a message class and _value_ the service identifier of its handler. |
|
| 26 | + */ |
|
| 27 | + public function __construct( |
|
| 28 | + private ContainerInterface $container, |
|
| 29 | + private array $handlers |
|
| 30 | + ) { |
|
| 31 | + $this->container = $container; |
|
| 32 | + $this->handlers = $handlers; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function getHandlerForMessage(object $message): callable |
|
| 36 | + { |
|
| 37 | + $class = get_class($message); |
|
| 38 | + $id = $this->handlers[$class] ?? null; |
|
| 39 | + |
|
| 40 | + if (!$id) { |
|
| 41 | + throw new NotFound("No handler for messages of type `$class`."); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + try { |
|
| 45 | + return $this->container->get($id); // @phpstan-ignore-line |
|
| 46 | + } catch (NotFoundExceptionInterface $e) { |
|
| 47 | + throw new NotFound("No handler for messages of type `$class`.", $e); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -16,32 +16,32 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class AssertingDispatcher implements Dispatcher |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var callable |
|
| 21 | - */ |
|
| 22 | - private $assertion; |
|
| 19 | + /** |
|
| 20 | + * @var callable |
|
| 21 | + */ |
|
| 22 | + private $assertion; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param callable $assertion |
|
| 26 | - * A callable that should throw an exception if the message shouldn't be dispatched. |
|
| 27 | - */ |
|
| 28 | - public function __construct( |
|
| 29 | - private Dispatcher $dispatcher, |
|
| 30 | - callable $assertion |
|
| 31 | - ) { |
|
| 32 | - $this->dispatcher = $dispatcher; |
|
| 33 | - $this->assertion = $assertion; |
|
| 34 | - } |
|
| 24 | + /** |
|
| 25 | + * @param callable $assertion |
|
| 26 | + * A callable that should throw an exception if the message shouldn't be dispatched. |
|
| 27 | + */ |
|
| 28 | + public function __construct( |
|
| 29 | + private Dispatcher $dispatcher, |
|
| 30 | + callable $assertion |
|
| 31 | + ) { |
|
| 32 | + $this->dispatcher = $dispatcher; |
|
| 33 | + $this->assertion = $assertion; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param object $message |
|
| 38 | - * |
|
| 39 | - * @return mixed |
|
| 40 | - */ |
|
| 41 | - public function dispatch(object $message) |
|
| 42 | - { |
|
| 43 | - ($this->assertion)($message); |
|
| 36 | + /** |
|
| 37 | + * @param object $message |
|
| 38 | + * |
|
| 39 | + * @return mixed |
|
| 40 | + */ |
|
| 41 | + public function dispatch(object $message) |
|
| 42 | + { |
|
| 43 | + ($this->assertion)($message); |
|
| 44 | 44 | |
| 45 | - return $this->dispatcher->dispatch($message); |
|
| 46 | - } |
|
| 45 | + return $this->dispatcher->dispatch($message); |
|
| 46 | + } |
|
| 47 | 47 | } |