Completed
Pull Request — master (#67)
by Ross
04:58
created

CommandHandlerPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 30
ccs 12
cts 12
cp 1
rs 10
c 3
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 17 2
1
<?php
2
3
namespace League\Tactician\Bundle\DependencyInjection\Compiler;
4
5
use League\Tactician\Bundle\DependencyInjection\Compiler\BusBuilder\BusBuilder;
6
use League\Tactician\Bundle\DependencyInjection\Compiler\BusBuilder\BusBuildersFromConfig;
7
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\HandlerMapping;
8
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\Routing;
9
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
12
/**
13
 * This compiler pass maps Handler DI tags to specific commands.
14
 */
15
class CommandHandlerPass implements CompilerPassInterface
16
{
17
    /**
18
     * @var HandlerMapping
19
     */
20
    private $handlerMapping;
21
22 72
    public function __construct(HandlerMapping $mappingStrategy)
23
    {
24 72
        $this->handlerMapping = $mappingStrategy;
25 72
    }
26
27 69
    public function process(ContainerBuilder $container)
28
    {
29 69
        $builders = BusBuildersFromConfig::convert($container->getExtensionConfig('tactician')[0]);
30
31 69
        $routing = $this->handlerMapping->build($container, $builders->createBlankRouting());
32
33
        // Register the completed builders in our container
34 66
        foreach ($builders as $builder) {
35
            /** @var BusBuilder $builder */
36 66
            $builder->registerInContainer($container, $routing->commandToServiceMapping($builder->id()));
37
        }
38
39
        // Setup default aliases
40 66
        $container->setAlias('tactician.commandbus', $builders->defaultBus()->serviceId());
41 66
        $container->setAlias('tactician.handler.locator.symfony', $builders->defaultBus()->locatorServiceId());
42 66
        $container->setAlias('tactician.middleware.command_handler', $builders->defaultBus()->commandHandlerMiddlewareId());
43 66
    }
44
}
45