/
HandlerLocator.php
41 lines (33 loc) · 1.07 KB
/
HandlerLocator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Messenger\Handler\Locator;
use Symfony\Component\Messenger\Exception\NoHandlerForMessageException;
/**
* @author Samuel Roze <samuel.roze@gmail.com>
*/
class HandlerLocator implements HandlerLocatorInterface
{
/**
* Maps a message (its class) to a given handler.
*/
private $messageToHandlerMapping;
public function __construct(array $messageToHandlerMapping = array())
{
$this->messageToHandlerMapping = $messageToHandlerMapping;
}
public function resolve($message): callable
{
$messageKey = \get_class($message);
if (!isset($this->messageToHandlerMapping[$messageKey])) {
throw new NoHandlerForMessageException(sprintf('No handler for message "%s".', $messageKey));
}
return $this->messageToHandlerMapping[$messageKey];
}
}