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

TacticianBundle::defaultMappingStrategy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace League\Tactician\Bundle;
4
5
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\ClassNameMapping;
6
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\CompositeMapping;
7
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\HandlerMapping;
8
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\TypeHintMapping;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use League\Tactician\Bundle\DependencyInjection\Compiler;
11
use League\Tactician\Bundle\DependencyInjection\TacticianExtension;
12
use Symfony\Component\HttpKernel\Bundle\Bundle;
13
14
class TacticianBundle extends Bundle
15
{
16
    /**
17
     * @var HandlerMapping
18
     */
19
    private $handlerMapping;
20
21 60
    public function __construct(HandlerMapping $handlerMapping = null)
22
    {
23 60
        if ($handlerMapping === null) {
24 60
            $handlerMapping = static::defaultMappingStrategy();
25
        }
26
27 60
        $this->handlerMapping = $handlerMapping;
28 60
    }
29
30
31 60
    public function build(ContainerBuilder $container)
32
    {
33 60
        parent::build($container);
34 60
        $container->addCompilerPass(new Compiler\DoctrineMiddlewarePass());
35 60
        $container->addCompilerPass(new Compiler\ValidatorMiddlewarePass());
36 60
        $container->addCompilerPass(new Compiler\SecurityMiddlewarePass());
37 60
        $container->addCompilerPass(new Compiler\CommandHandlerPass($this->handlerMapping));
38 60
    }
39
40 60
    public function getContainerExtension()
41
    {
42 60
        return new TacticianExtension();
43
    }
44
45 60
    public static function defaultMappingStrategy(): HandlerMapping
46
    {
47 60
        return new CompositeMapping(new TypeHintMapping(), new ClassNameMapping());
48
    }
49
}
50