BootstrapProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
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 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
    {
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
        {
62 9
            $string = is_string($provider) === true;
63
64 9
            $string === true && $provider = new $provider;
65
66 9
            $container = $provider->register($container);
67
68 9
            $this->providers[] = get_class($provider);
69 3
        }
70
71 9
        return $container;
72
    }
73
}
74