@@ -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); // @phpstan-ignore-line |
|
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); // @phpstan-ignore-line |
|
55 | + } catch (NotFoundExceptionInterface $e) { |
|
56 | + throw new NotFound("No handler for messages of type `$class`.", $e); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | } |