Passed
Push — master ( 947dd1...26228a )
by Rougin
02:38
created

BootstrapProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 56
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A register() 0 19 3
1
<?php
2
3
namespace App\Zapheus;
4
5
use Zapheus\Container\WritableInterface;
6
use Zapheus\Provider\Configuration;
7
use Zapheus\Provider\ProviderInterface;
8
9
/**
10
 * Bootstrap Provider
11
 *
12
 * @package App
13
 * @author  Rougin Royce Gutib <[email protected]>
14
 */
15
class BootstrapProvider implements ProviderInterface
16
{
17
    /**
18
     * Full path for the configuration directory.
19
     *
20
     * @var string
21
     */
22
    protected $config;
23
24
    /**
25
     * An array of loaded providers.
26
     *
27
     * @var string[]
28
     */
29
    protected $providers = array();
30
31
    /**
32
     * Initializes the provider instance.
33
     *
34
     * @param string $root
35
     * @param string $config
36
     */
37 9
    public function __construct($root, $config = 'app/config')
38 6
    {
39 9
        $dotenv = new \Dotenv\Dotenv($root);
40
41 9
        $dotenv->load();
42
43 9
        $this->config = $root . $config;
44 9
    }
45
46
    /**
47
     * Registers the bindings in the container.
48
     *
49
     * @param  \Zapheus\Container\WritableInterface $container
50
     * @return \Zapheus\Container\ContainerInterface
51
     */
52 9
    public function register(WritableInterface $container)
53
    {
54 9
        $config = new Configuration(array());
55
56 9
        $config->load((string) $this->config);
57
58 9
        $providers = $config->get('providers.zapheus');
59
60 9
        foreach ((array) $providers as $provider) {
61 9
            $string = is_string($provider) === true;
62
63 9
            $string === true && $provider = new $provider;
64
65 9
            $container = $provider->register($container);
66
67 9
            $this->providers[] = get_class($provider);
68 6
        }
69
70 9
        return $container;
71
    }
72
}
73