MappingLocator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace TillKruss\LaravelTactician\Locators;
4
5
use Illuminate\Contracts\Container\Container;
6
use League\Tactician\Handler\Locator\HandlerLocator;
7
use League\Tactician\Exception\MissingHandlerException;
8
use Illuminate\Contracts\Config\Repository as Configuration;
9
10
class MappingLocator implements HandlerLocator
11
{
12
    /**
13
     * The container instance.
14
     *
15
     * @var \Illuminate\Contracts\Container\Container
16
     */
17
    protected $container;
18
19
    /**
20
     * The configuration instance.
21
     *
22
     * @var \Illuminate\Contracts\Config\Repository
23
     */
24
    protected $config;
25
26
    /**
27
     * Create a new mapping locator instance.
28
     *
29
     * @param \Illuminate\Contracts\Container\Container  $container
30
     * @param \Illuminate\Contracts\Config\Repository    $config
31
     */
32
    public function __construct(Container $container, Configuration $config)
33
    {
34
        $this->container = $container;
35
        $this->config = $config;
36
    }
37
38
    /**
39
     * Returns the handler bound to the command's class name.
40
     *
41
     * @param  string  $command
42
     * @return object
43
     *
44
     * @throws \League\Tactician\Exception\MissingHandlerException
45
     */
46
    public function getHandlerForCommand($command)
47
    {
48
        $handlers = $this->config->get('tactician.handlers', []);
49
50
        if (! isset($handlers[$command]) || ! class_exists($handlers[$command])) {
51
            throw MissingHandlerException::forCommand($command);
52
        }
53
54
        return $this->container->make($handlers[$command]);
55
    }
56
}
57