Completed
Push — master ( 03d9da...2dac9a )
by Tom
13s
created

InflectorServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
namespace TomPHP\ContainerConfigurator\League;
4
5
use League\Container\ServiceProvider\AbstractServiceProvider;
6
use League\Container\ServiceProvider\BootableServiceProviderInterface;
7
use TomPHP\ContainerConfigurator\InflectorConfig;
8
use TomPHP\ContainerConfigurator\InflectorDefinition;
9
10
final class InflectorServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface
11
{
12
    /**
13
     * @var InflectorConfig
14
     */
15
    private $config;
16
17
    /**
18
     * @api
19
     *
20
     * @param InflectorConfig $config
21
     */
22
    public function __construct(InflectorConfig $config)
23
    {
24
        $this->config = $config;
25
    }
26
27
    public function register()
28
    {
29
    }
30
31
    public function boot()
32
    {
33
        foreach ($this->config as $definition) {
34
            $this->configureInterface($definition);
35
        }
36
    }
37
38
    /**
39
     * @param InflectorDefinition $definition
40
     */
41
    private function configureInterface(InflectorDefinition $definition)
42
    {
43
        foreach ($definition->getMethods() as $method => $args) {
44
            $this->addInflectorMethod(
45
                $definition->getInterface(),
46
                $method,
47
                $args
48
            );
49
        }
50
    }
51
52
    /**
53
     * @param string $interface
54
     * @param string $method
55
     * @param array  $args
56
     */
57
    private function addInflectorMethod($interface, $method, array $args)
58
    {
59
        $this->getContainer()
60
            ->inflector($interface)
61
            ->invokeMethod($method, $args);
62
    }
63
}
64