File tree Expand file tree Collapse file tree 3 files changed +60
-46
lines changed
Filter options
src/Symfony/Component/Messenger/Handler/Locator Expand file tree Collapse file tree 3 files changed +60
-46
lines changed
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Component \Messenger \Handler \Locator ;
13
+
14
+ use Symfony \Component \Messenger \Exception \NoHandlerForMessageException ;
15
+
16
+ /**
17
+ * @author Miha Vrhovnik <miha.vrhovnik@gmail.com>
18
+ * @author Samuel Roze <samuel.roze@gmail.com>
19
+ */
20
+ abstract class AbstractHandlerLocator implements HandlerLocatorInterface
21
+ {
22
+ public function resolve ($ message ): callable
23
+ {
24
+ $ messageClass = \get_class ($ message );
25
+
26
+ if (null === $ handler = $ this ->resolveFromClass ($ messageClass )) {
27
+ throw new NoHandlerForMessageException (sprintf ('No handler for message "%s". ' , $ messageClass ));
28
+ }
29
+
30
+ return $ handler ;
31
+ }
32
+
33
+ private function resolveFromClass (string $ class ): ?callable
34
+ {
35
+ if ($ handler = $ this ->getHandler ($ class )) {
36
+ return $ handler ;
37
+ }
38
+
39
+ foreach (class_implements ($ class , false ) as $ interface ) {
40
+ if ($ handler = $ this ->getHandler ($ interface )) {
41
+ return $ handler ;
42
+ }
43
+ }
44
+
45
+ foreach (class_parents ($ class , false ) as $ parent ) {
46
+ if ($ handler = $ this ->getHandler ($ parent )) {
47
+ return $ handler ;
48
+ }
49
+ }
50
+
51
+ return null ;
52
+ }
53
+
54
+ abstract protected function getHandler (string $ class );
55
+ }
Original file line number Diff line number Diff line change 12
12
namespace Symfony \Component \Messenger \Handler \Locator ;
13
13
14
14
use Psr \Container \ContainerInterface ;
15
- use Symfony \Component \Messenger \Exception \NoHandlerForMessageException ;
16
15
17
16
/**
18
17
* @author Miha Vrhovnik <miha.vrhovnik@gmail.com>
19
18
* @author Samuel Roze <samuel.roze@gmail.com>
20
19
*/
21
- class ContainerHandlerLocator implements HandlerLocatorInterface
20
+ class ContainerHandlerLocator extends AbstractHandlerLocator
22
21
{
23
22
private $ container ;
24
23
@@ -27,39 +26,7 @@ public function __construct(ContainerInterface $container)
27
26
$ this ->container = $ container ;
28
27
}
29
28
30
- public function resolve ($ message ): callable
31
- {
32
- $ messageClass = \get_class ($ message );
33
-
34
- if (null === $ handler = $ this ->resolveFromClass ($ messageClass )) {
35
- throw new NoHandlerForMessageException (sprintf ('No handler for message "%s". ' , $ messageClass ));
36
- }
37
-
38
- return $ handler ;
39
- }
40
-
41
- private function resolveFromClass ($ class ): ?callable
42
- {
43
- if ($ handler = $ this ->getHandler ($ class )) {
44
- return $ handler ;
45
- }
46
-
47
- foreach (class_implements ($ class , false ) as $ interface ) {
48
- if ($ handler = $ this ->getHandler ($ interface )) {
49
- return $ handler ;
50
- }
51
- }
52
-
53
- foreach (class_parents ($ class , false ) as $ parent ) {
54
- if ($ handler = $ this ->getHandler ($ parent )) {
55
- return $ handler ;
56
- }
57
- }
58
-
59
- return null ;
60
- }
61
-
62
- private function getHandler ($ class )
29
+ protected function getHandler (string $ class )
63
30
{
64
31
$ handlerKey = 'handler. ' .$ class ;
65
32
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Messenger \Handler \Locator ;
13
13
14
- use Symfony \Component \Messenger \Exception \NoHandlerForMessageException ;
15
-
16
14
/**
17
15
* @author Samuel Roze <samuel.roze@gmail.com>
18
16
*/
19
- class HandlerLocator implements HandlerLocatorInterface
17
+ class HandlerLocator extends AbstractHandlerLocator
20
18
{
21
19
/**
22
20
* Maps a message (its class) to a given handler.
@@ -28,14 +26,8 @@ public function __construct(array $messageToHandlerMapping = array())
28
26
$ this ->messageToHandlerMapping = $ messageToHandlerMapping ;
29
27
}
30
28
31
- public function resolve ( $ message ): callable
29
+ protected function getHandler ( string $ class )
32
30
{
33
- $ messageKey = \get_class ($ message );
34
-
35
- if (!isset ($ this ->messageToHandlerMapping [$ messageKey ])) {
36
- throw new NoHandlerForMessageException (sprintf ('No handler for message "%s". ' , $ messageKey ));
37
- }
38
-
39
- return $ this ->messageToHandlerMapping [$ messageKey ];
31
+ return $ this ->messageToHandlerMapping [$ class ] ?? null ;
40
32
}
41
33
}
You can’t perform that action at this time.
0 commit comments