Completed
Pull Request — master (#20)
by
unknown
02:20
created

TacticianExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadInternal() 0 7 1
A getAlias() 0 4 1
A configureCommandBuses() 0 19 3
1
<?php namespace League\Tactician\Bundle\DependencyInjection;
2
3
use Symfony\Component\Config\FileLocator;
4
use Symfony\Component\DependencyInjection\Definition;
5
use Symfony\Component\DependencyInjection\Loader;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
9
10
class TacticianExtension extends ConfigurableExtension
11
{
12
    /**
13
     * Configures the passed container according to the merged configuration.
14
     *
15
     * @param array $mergedConfig
16
     * @param ContainerBuilder $container
17
     */
18 9
    protected function loadInternal(array $mergedConfig, ContainerBuilder $container)
19
    {
20 9
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/services'));
21 9
        $loader->load('services.yml');
22
23 9
        $this->configureCommandBuses($mergedConfig, $container);
24 9
    }
25
26 9
    public function getAlias()
27
    {
28 9
        return 'tactician';
29
    }
30
31
    /**
32
     * @param array $mergedConfig
33
     * @param ContainerBuilder $container
34
     */
35 9
    private function configureCommandBuses(array $mergedConfig, ContainerBuilder $container)
36
    {
37 9
        foreach ($mergedConfig['commandbus'] as $commandBusName => $commandBusConfig) {
38 9
            $middlewares = array_map(
39 9
                function ($middlewareServiceId) {
40 9
                    return new Reference($middlewareServiceId);
41 9
                },
42 9
                $commandBusConfig['middleware']
43 9
            );
44
45 9
            $serviceName = 'tactician.commandbus.' . $commandBusName;
46 9
            $definition = new Definition($container->getParameter('tactician.commandbus.class'), [$middlewares]);
47 9
            $container->setDefinition($serviceName, $definition);
48
49 9
            if ($commandBusName === $mergedConfig['default_bus']) {
50 9
                $container->setAlias('tactician.commandbus', $serviceName);
51 9
            }
52 9
        }
53 9
    }
54
}
55