| @@ -16,28 +16,28 @@ | ||
| 16 | 16 | */ | 
| 17 | 17 | final class SimpleHandlerProvider implements HandlerProvider | 
| 18 | 18 |  { | 
| 19 | - /** | |
| 20 | - * @var array<string, callable> | |
| 21 | - */ | |
| 22 | - private $handlers; | |
| 19 | + /** | |
| 20 | + * @var array<string, callable> | |
| 21 | + */ | |
| 22 | + private $handlers; | |
| 23 | 23 | |
| 24 | - /** | |
| 25 | - * @param array<string, callable> $handlers | |
| 26 | - */ | |
| 27 | - public function __construct(array $handlers) | |
| 28 | -    { | |
| 29 | - $this->handlers = $handlers; | |
| 30 | - } | |
| 24 | + /** | |
| 25 | + * @param array<string, callable> $handlers | |
| 26 | + */ | |
| 27 | + public function __construct(array $handlers) | |
| 28 | +	{ | |
| 29 | + $this->handlers = $handlers; | |
| 30 | + } | |
| 31 | 31 | |
| 32 | - public function getHandlerForMessage(object $message): callable | |
| 33 | -    { | |
| 34 | - $class = get_class($message); | |
| 35 | - $handler = $this->handlers[$class] ?? null; | |
| 32 | + public function getHandlerForMessage(object $message): callable | |
| 33 | +	{ | |
| 34 | + $class = get_class($message); | |
| 35 | + $handler = $this->handlers[$class] ?? null; | |
| 36 | 36 | |
| 37 | -        if (!$handler) { | |
| 38 | -            throw new NotFound("No handler for messages of type `$class`."); | |
| 39 | - } | |
| 37 | +		if (!$handler) { | |
| 38 | +			throw new NotFound("No handler for messages of type `$class`."); | |
| 39 | + } | |
| 40 | 40 | |
| 41 | - return $handler; | |
| 42 | - } | |
| 41 | + return $handler; | |
| 42 | + } | |
| 43 | 43 | } | 
| @@ -16,15 +16,15 @@ | ||
| 16 | 16 | */ | 
| 17 | 17 | interface HandlerProvider | 
| 18 | 18 |  { | 
| 19 | - /** | |
| 20 | - * @param object $message | |
| 21 | - * A message for which to return the relevant handler. | |
| 22 | - * | |
| 23 | - * @return callable | |
| 24 | - * A callable that MUST be type-compatible with $message. | |
| 25 | - * | |
| 26 | - * @throws NotFound | |
| 27 | - * The handler for the message cannot the found. | |
| 28 | - */ | |
| 29 | - public function getHandlerForMessage(object $message): callable; | |
| 19 | + /** | |
| 20 | + * @param object $message | |
| 21 | + * A message for which to return the relevant handler. | |
| 22 | + * | |
| 23 | + * @return callable | |
| 24 | + * A callable that MUST be type-compatible with $message. | |
| 25 | + * | |
| 26 | + * @throws NotFound | |
| 27 | + * The handler for the message cannot the found. | |
| 28 | + */ | |
| 29 | + public function getHandlerForMessage(object $message): callable; | |
| 30 | 30 | } | 
| @@ -15,8 +15,8 @@ | ||
| 15 | 15 | |
| 16 | 16 | class QueryDispatcher extends SimpleDispatcher | 
| 17 | 17 |  { | 
| 18 | - public function __construct(QueryHandlerProvider $handlerProvider) | |
| 19 | -    { | |
| 20 | - parent::__construct($handlerProvider); | |
| 21 | - } | |
| 18 | + public function __construct(QueryHandlerProvider $handlerProvider) | |
| 19 | +	{ | |
| 20 | + parent::__construct($handlerProvider); | |
| 21 | + } | |
| 22 | 22 | } | 
| @@ -20,40 +20,40 @@ | ||
| 20 | 20 | |
| 21 | 21 | class ContainerHandlerProvider implements HandlerProvider | 
| 22 | 22 |  { | 
| 23 | - /** | |
| 24 | - * @var ContainerInterface | |
| 25 | - */ | |
| 26 | - private $container; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * @var array<string, string> | |
| 30 | - */ | |
| 31 | - private $handlers; | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * @param array<string, string> $mapping | |
| 35 | - * An array of key/value pairs where _key_ is a message class and _value_ the service | |
| 36 | - * identifier of its handler. | |
| 37 | - */ | |
| 38 | - public function __construct(ContainerInterface $container, array $mapping) | |
| 39 | -    { | |
| 40 | - $this->handlers = $mapping; | |
| 41 | - $this->container = $container; | |
| 42 | - } | |
| 43 | - | |
| 44 | - public function getHandlerForMessage(object $message): callable | |
| 45 | -    { | |
| 46 | - $class = get_class($message); | |
| 47 | - $id = $this->handlers[$class] ?? null; | |
| 48 | - | |
| 49 | -        if (!$id) { | |
| 50 | -            throw new NotFound("No handler for messages of type `$class`."); | |
| 51 | - } | |
| 52 | - | |
| 53 | -        try { | |
| 54 | - return $this->container->get($id); | |
| 55 | -        } catch (NotFoundExceptionInterface $e) { | |
| 56 | -            throw new NotFound("No handler for messages of type `$class`.", $e); | |
| 57 | - } | |
| 58 | - } | |
| 23 | + /** | |
| 24 | + * @var ContainerInterface | |
| 25 | + */ | |
| 26 | + private $container; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * @var array<string, string> | |
| 30 | + */ | |
| 31 | + private $handlers; | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * @param array<string, string> $mapping | |
| 35 | + * An array of key/value pairs where _key_ is a message class and _value_ the service | |
| 36 | + * identifier of its handler. | |
| 37 | + */ | |
| 38 | + public function __construct(ContainerInterface $container, array $mapping) | |
| 39 | +	{ | |
| 40 | + $this->handlers = $mapping; | |
| 41 | + $this->container = $container; | |
| 42 | + } | |
| 43 | + | |
| 44 | + public function getHandlerForMessage(object $message): callable | |
| 45 | +	{ | |
| 46 | + $class = get_class($message); | |
| 47 | + $id = $this->handlers[$class] ?? null; | |
| 48 | + | |
| 49 | +		if (!$id) { | |
| 50 | +			throw new NotFound("No handler for messages of type `$class`."); | |
| 51 | + } | |
| 52 | + | |
| 53 | +		try { | |
| 54 | + return $this->container->get($id); | |
| 55 | +		} catch (NotFoundExceptionInterface $e) { | |
| 56 | +			throw new NotFound("No handler for messages of type `$class`.", $e); | |
| 57 | + } | |
| 58 | + } | |
| 59 | 59 | } | 
| @@ -15,8 +15,8 @@ | ||
| 15 | 15 | |
| 16 | 16 | class CommandDispatcher extends SimpleDispatcher | 
| 17 | 17 |  { | 
| 18 | - public function __construct(CommandHandlerProvider $handlerProvider) | |
| 19 | -    { | |
| 20 | - parent::__construct($handlerProvider); | |
| 21 | - } | |
| 18 | + public function __construct(CommandHandlerProvider $handlerProvider) | |
| 19 | +	{ | |
| 20 | + parent::__construct($handlerProvider); | |
| 21 | + } | |
| 22 | 22 | } | 
| @@ -16,36 +16,36 @@ | ||
| 16 | 16 | */ | 
| 17 | 17 | class AssertingDispatcher implements Dispatcher | 
| 18 | 18 |  { | 
| 19 | - /** | |
| 20 | - * @var Dispatcher | |
| 21 | - */ | |
| 22 | - private $dispatcher; | |
| 19 | + /** | |
| 20 | + * @var Dispatcher | |
| 21 | + */ | |
| 22 | + private $dispatcher; | |
| 23 | 23 | |
| 24 | - /** | |
| 25 | - * @var callable | |
| 26 | - */ | |
| 27 | - private $assertion; | |
| 24 | + /** | |
| 25 | + * @var callable | |
| 26 | + */ | |
| 27 | + private $assertion; | |
| 28 | 28 | |
| 29 | - /** | |
| 30 | - * @param Dispatcher $dispatcher | |
| 31 | - * @param callable $assertion A callable that should throw an exception if the message shouldn't | |
| 32 | - * be dispatched. | |
| 33 | - */ | |
| 34 | - public function __construct(Dispatcher $dispatcher, callable $assertion) | |
| 35 | -    { | |
| 36 | - $this->dispatcher = $dispatcher; | |
| 37 | - $this->assertion = $assertion; | |
| 38 | - } | |
| 29 | + /** | |
| 30 | + * @param Dispatcher $dispatcher | |
| 31 | + * @param callable $assertion A callable that should throw an exception if the message shouldn't | |
| 32 | + * be dispatched. | |
| 33 | + */ | |
| 34 | + public function __construct(Dispatcher $dispatcher, callable $assertion) | |
| 35 | +	{ | |
| 36 | + $this->dispatcher = $dispatcher; | |
| 37 | + $this->assertion = $assertion; | |
| 38 | + } | |
| 39 | 39 | |
| 40 | - /** | |
| 41 | - * @param object $message | |
| 42 | - * | |
| 43 | - * @return mixed | |
| 44 | - */ | |
| 45 | - public function dispatch(object $message) | |
| 46 | -    { | |
| 47 | - ($this->assertion)($message); | |
| 40 | + /** | |
| 41 | + * @param object $message | |
| 42 | + * | |
| 43 | + * @return mixed | |
| 44 | + */ | |
| 45 | + public function dispatch(object $message) | |
| 46 | +	{ | |
| 47 | + ($this->assertion)($message); | |
| 48 | 48 | |
| 49 | - return $this->dispatcher->dispatch($message); | |
| 50 | - } | |
| 49 | + return $this->dispatcher->dispatch($message); | |
| 50 | + } | |
| 51 | 51 | } | 
| @@ -16,18 +16,18 @@ | ||
| 16 | 16 | */ | 
| 17 | 17 | class SimpleDispatcher implements Dispatcher | 
| 18 | 18 |  { | 
| 19 | - /** | |
| 20 | - * @var HandlerProvider | |
| 21 | - */ | |
| 22 | - private $handler_provider; | |
| 19 | + /** | |
| 20 | + * @var HandlerProvider | |
| 21 | + */ | |
| 22 | + private $handler_provider; | |
| 23 | 23 | |
| 24 | - public function __construct(HandlerProvider $handlerProvider) | |
| 25 | -    { | |
| 26 | - $this->handler_provider = $handlerProvider; | |
| 27 | - } | |
| 24 | + public function __construct(HandlerProvider $handlerProvider) | |
| 25 | +	{ | |
| 26 | + $this->handler_provider = $handlerProvider; | |
| 27 | + } | |
| 28 | 28 | |
| 29 | - public function dispatch(object $message) | |
| 30 | -    { | |
| 31 | - return $this->handler_provider->getHandlerForMessage($message)($message); | |
| 32 | - } | |
| 29 | + public function dispatch(object $message) | |
| 30 | +	{ | |
| 31 | + return $this->handler_provider->getHandlerForMessage($message)($message); | |
| 32 | + } | |
| 33 | 33 | } | 
| @@ -19,8 +19,8 @@ | ||
| 19 | 19 | */ | 
| 20 | 20 | final class NotFound extends LogicException implements Exception | 
| 21 | 21 |  { | 
| 22 | - public function __construct(string $message, Throwable $previous = null) | |
| 23 | -    { | |
| 24 | - parent::__construct($message, 0, $previous); | |
| 25 | - } | |
| 22 | + public function __construct(string $message, Throwable $previous = null) | |
| 23 | +	{ | |
| 24 | + parent::__construct($message, 0, $previous); | |
| 25 | + } | |
| 26 | 26 | } | 
| @@ -16,15 +16,15 @@ | ||
| 16 | 16 | */ | 
| 17 | 17 | interface Dispatcher | 
| 18 | 18 |  { | 
| 19 | - /** | |
| 20 | - * @param object $message | |
| 21 | - * The message to dispatch. | |
| 22 | - * | |
| 23 | - * @return mixed | |
| 24 | - * Result type depends on the handler. | |
| 25 | - * | |
| 26 | - * @throws NotFound | |
| 27 | - * The handler for the message cannot the found. | |
| 28 | - */ | |
| 29 | - public function dispatch(object $message); | |
| 19 | + /** | |
| 20 | + * @param object $message | |
| 21 | + * The message to dispatch. | |
| 22 | + * | |
| 23 | + * @return mixed | |
| 24 | + * Result type depends on the handler. | |
| 25 | + * | |
| 26 | + * @throws NotFound | |
| 27 | + * The handler for the message cannot the found. | |
| 28 | + */ | |
| 29 | + public function dispatch(object $message); | |
| 30 | 30 | } |