1 | <?php |
||
9 | abstract class TagBasedMapping implements HandlerMapping |
||
10 | { |
||
11 | const TAG_NAME = 'tactician.handler'; |
||
12 | |||
13 | 132 | public function build(ContainerBuilder $container, Routing $routing): Routing |
|
14 | { |
||
15 | 132 | foreach ($container->findTaggedServiceIds(self::TAG_NAME) as $serviceId => $tags) { |
|
16 | 96 | foreach ($tags as $attributes) { |
|
17 | 96 | $this->mapServiceByTag($container, $routing, $serviceId, $attributes); |
|
18 | } |
||
19 | } |
||
20 | |||
21 | 126 | return $routing; |
|
22 | } |
||
23 | |||
24 | /** |
||
25 | * @param ContainerBuilder $container |
||
26 | * @param Routing $routing |
||
27 | * @param $serviceId |
||
28 | * @param $attributes |
||
29 | */ |
||
30 | 96 | private function mapServiceByTag(ContainerBuilder $container, Routing $routing, $serviceId, $attributes) |
|
31 | { |
||
32 | 96 | $definition = $container->getDefinition($serviceId); |
|
33 | |||
34 | 96 | if (!$this->isSupported($container, $definition, $attributes)) { |
|
35 | 36 | return; |
|
36 | } |
||
37 | |||
38 | 90 | foreach ($this->findCommandsForService($container, $definition, $attributes) as $commandClassName) { |
|
39 | 66 | if (isset($attributes['bus'])) { |
|
40 | 27 | $routing->routeToBus($attributes['bus'], $commandClassName, $serviceId); |
|
41 | } else { |
||
42 | 51 | $routing->routeToAllBuses($commandClassName, $serviceId); |
|
43 | } |
||
44 | } |
||
45 | 81 | } |
|
46 | |||
47 | abstract protected function isSupported(ContainerBuilder $container, Definition $definition, array $tagAttributes): bool; |
||
48 | |||
49 | abstract protected function findCommandsForService(ContainerBuilder $container, Definition $definition, array $tagAttributes): array; |
||
50 | } |
||
51 |