Completed
Push — master ( 59f47f...d310cf )
by Rougin
02:23
created

IlluminateProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 67
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A register() 0 18 3
A container() 0 14 2
1
<?php
2
3
namespace Zapheus\Bridge\Illuminate;
4
5
use Illuminate\Config\Repository;
6
use Illuminate\Container\Container as IlluminateContainer;
7
use Zapheus\Container\WritableInterface;
8
use Zapheus\Provider\ProviderInterface;
9
10
/**
11
 * Illuminate Provider
12
 *
13
 * @package Zapheus
14
 * @author  Rougin Royce Gutib <[email protected]>
15
 */
16
class IlluminateProvider implements ProviderInterface
17
{
18
    const CONTAINER = 'Illuminate\Container\Container';
19
20
    const LOADER = 'Illuminate\Config\LoaderInterface';
21
22
    /**
23
     * @var string[]
24
     */
25
    protected $providers;
26
27
    /**
28
     * Initializes the provider instance.
29
     *
30
     * @param string[] $providers
31
     */
32 3
    public function __construct(array $providers)
33
    {
34 3
        $this->providers = $providers;
35 3
    }
36
37
    /**
38
     * Registers the bindings in the container.
39
     *
40
     * @param  \Zapheus\Container\WritableInterface $container
41
     * @return \Zapheus\Container\ContainerInterface
42
     */
43 3
    public function register(WritableInterface $container)
44
    {
45 3
        $illuminate = $this->container($container);
46
47 3
        foreach ($this->providers as $item) {
48 3
            $provider = new $item($illuminate);
49
50 3
            $exists = method_exists($provider, 'boot');
51
52 3
            $provider->register();
53
54 3
            $exists === true && $provider->boot();
55 1
        }
56
57 3
        $container->set(self::CONTAINER, $illuminate);
58
59 3
        return $container;
60
    }
61
62
    /**
63
     * Returns a \Illuminate\Container\Container instance.
64
     *
65
     * @param  \Zapheus\Container\WritableInterface $container
66
     * @return \Illuminate\Container\Container
67
     */
68 3
    protected function container(WritableInterface $container)
69
    {
70 3
        $laravel = new IlluminateContainer;
71
72 3
        if (interface_exists(self::LOADER) === false) {
73 3
            $config = $container->get(self::CONFIG);
74
75 3
            $items = $config->get('illuminate', array());
76
77 3
            $laravel['config'] = new Repository($items);
78 1
        }
79
80 3
        return $laravel;
81
    }
82
}
83