|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ================================== |
|
4
|
|
|
* Responsible PHP API |
|
5
|
|
|
* ================================== |
|
6
|
|
|
* |
|
7
|
|
|
* @link Git https://github.com/vince-scarpa/responsibleAPI.git |
|
8
|
|
|
* |
|
9
|
|
|
* @api Responible API |
|
10
|
|
|
* @package responsible\core\configuration |
|
11
|
|
|
* |
|
12
|
|
|
* @author Vince scarpa <[email protected]> |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace responsible\core\configuration; |
|
16
|
|
|
|
|
17
|
|
|
use josegonzalez; |
|
18
|
|
|
|
|
19
|
|
|
class config |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* ResponsibleAPI software version |
|
23
|
|
|
* @var float |
|
24
|
|
|
*/ |
|
25
|
|
|
private const MAJOR_VERSION = 1.5; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* [$DEFAULTS] |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
private $DEFAULTS; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* [$CONFIG] |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
private $CONFIG; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* [$root Root path] |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
private $root = ''; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* [responsibleDefault Responsible default options and config] |
|
47
|
|
|
* @param array|null $options |
|
48
|
|
|
* @return void |
|
49
|
|
|
*/ |
|
50
|
|
|
public function responsibleDefault($options = null) |
|
51
|
|
|
{ |
|
52
|
|
|
if (empty($this->root)) { |
|
53
|
|
|
$this->root = dirname(dirname(dirname(__DIR__))); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$ENV_FILE = $this->root . '/config/.config'; |
|
57
|
|
|
|
|
58
|
|
|
if (!file_exists($ENV_FILE)) { |
|
59
|
|
|
throw new \Exception( |
|
60
|
|
|
"No configuration file seems to exist. Please read the documentation on setting up a configuration file." |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->CONFIG = (new josegonzalez\Dotenv\Loader($ENV_FILE)) |
|
65
|
|
|
->parse() |
|
66
|
|
|
->toArray(); |
|
67
|
|
|
|
|
68
|
|
|
if (is_null($this->CONFIG) || empty($this->CONFIG)) { |
|
69
|
|
|
throw new \Exception( |
|
70
|
|
|
"No config specified in Responsible API class. Please read the documentation on configuration settings." |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$options['manifest'] = [ |
|
75
|
|
|
'major_version' => self::getVersion(), |
|
76
|
|
|
'description' => 'Appended by ResponsibleAPI' |
|
77
|
|
|
]; |
|
78
|
|
|
|
|
79
|
|
|
$DEFAULTS = [ |
|
80
|
|
|
'options' => $options, |
|
81
|
|
|
'config' => $this->CONFIG, |
|
82
|
|
|
]; |
|
83
|
|
|
|
|
84
|
|
|
$this->defaults($DEFAULTS); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* [defaults Defaults is a merged array of Config and Options] |
|
89
|
|
|
* @return void |
|
90
|
|
|
*/ |
|
91
|
|
|
private function defaults($defaults) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->DEFAULTS = $defaults; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* [getDefaults Get default config and options as a single array] |
|
98
|
|
|
* @return array |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getDefaults() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->DEFAULTS; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* [getConfig Get config array] |
|
107
|
|
|
* @return array |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getConfig() |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->DEFAULTS['config']; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* [getOptions description Get options array] |
|
116
|
|
|
* @return array |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getOptions() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->DEFAULTS['options']; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* [baseApiRoot Set the responsible API root directory] |
|
125
|
|
|
* @return void |
|
126
|
|
|
*/ |
|
127
|
|
|
public function baseApiRoot($directory) |
|
128
|
|
|
{ |
|
129
|
|
|
$this->root = $directory; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* [getVersion Get the ResponsibleAPI sowtware versions] |
|
134
|
|
|
* @return float |
|
135
|
|
|
*/ |
|
136
|
|
|
public static function getVersion() |
|
137
|
|
|
{ |
|
138
|
|
|
return self::MAJOR_VERSION; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|