Completed
Push — master ( 45dd31...d94b70 )
by Nikola
02:35
created

Options::getDiContainerFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the Phoundation package.
4
 *
5
 * Copyright (c) Nikola Posa
6
 *
7
 * For full copyright and license information, please refer to the LICENSE file,
8
 * located at the package root folder.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Phoundation\Bootstrap;
14
15
use Phoundation\Di\Container\Factory\FactoryInterface;
16
use Phoundation\Exception\InvalidBootstrapOptionsException;
17
18
/**
19
 * @author Nikola Posa <[email protected]>
20
 */
21
class Options
22
{
23
    /**
24
     * @var array
25
     */
26
    protected $config;
27
28
    /**
29
     * @var array
30
     */
31
    protected $configPaths;
32
33
    /**
34
     * @var array
35
     */
36
    protected $configGlobPaths;
37
38
    /**
39
     * @var callable
40
     */
41
    protected $diContainerFactory;
42
43
    /**
44
     * @var string
45
     */
46
    protected $diConfigKey;
47
48
    /**
49
     * @var string
50
     */
51
    protected $configServiceName;
52
53 7
    protected function __construct(
54
        array $config,
55
        array $configPaths,
56
        array $configGlobPaths,
57
        callable $diContainerFactory,
58
        string $diConfigKey,
59
        string $configServiceName
60
    ) {
61 7
        $this->config = $config;
62 7
        $this->configPaths = $configPaths;
63 7
        $this->configGlobPaths = $configGlobPaths;
64 7
        $this->diContainerFactory = $diContainerFactory;
65 7
        $this->diConfigKey = $diConfigKey;
66 7
        $this->configServiceName = $configServiceName;
67 7
    }
68
69 8
    public static function fromArray(array $options)
70
    {
71 8
        $options = array_merge([
72 8
            'config' => [],
73
            'config_paths' => [],
74
            'config_glob_paths' => [],
75
            'config_provider' => [],
76 8
            'di_config_key' => FactoryInterface::DEFAULT_DI_CONFIG_KEY,
77 8
            'config_service_name' => FactoryInterface::DEFAULT_CONFIG_SERVICE_NAME,
78
        ], $options);
79
80 8
        if (!isset($options['di_container_factory'])) {
81 1
            throw InvalidBootstrapOptionsException::forMissingDiContainerFactory();
82 7
        } elseif (is_string($options['di_container_factory'])) {
83 7
            $options['di_container_factory'] = new $options['di_container_factory']();
84
        }
85
86 7
        return new self(
87 7
            $options['config'],
88 7
            $options['config_paths'],
89 7
            $options['config_glob_paths'],
90 7
            $options['di_container_factory'],
91 7
            $options['di_config_key'],
92 7
            $options['config_service_name']
93
        );
94
    }
95
96 7
    public function getConfig() : array
97
    {
98 7
        return $this->config;
99
    }
100
101 7
    public function getConfigPaths() : array
102
    {
103 7
        return $this->configPaths;
104
    }
105
106 7
    public function getConfigGlobPaths() : array
107
    {
108 7
        return $this->configGlobPaths;
109
    }
110
111 7
    public function getDiContainerFactory() : callable
112
    {
113 7
        return $this->diContainerFactory;
114
    }
115
116 7
    public function getDiConfigKey() : string
117
    {
118 7
        return $this->diConfigKey;
119
    }
120
121 7
    public function getConfigServiceName() : string
122
    {
123 7
        return $this->configServiceName;
124
    }
125
}
126