1 | <?php |
||
12 | class Environment |
||
13 | { |
||
14 | /** |
||
15 | * Environment variable. Use Apache SetEnv or export in shell. |
||
16 | * |
||
17 | * @var string environment variable name |
||
18 | */ |
||
19 | protected $envName = 'APP_ENV'; |
||
20 | /** |
||
21 | * @var array list of valid modes |
||
22 | */ |
||
23 | protected $validModes = [ |
||
24 | 'dev', |
||
25 | 'test', |
||
26 | 'stage', |
||
27 | 'prod', |
||
28 | ]; |
||
29 | /** |
||
30 | * @var array configuration directory(s) |
||
31 | */ |
||
32 | protected $configDir = []; |
||
33 | /** |
||
34 | * @var string selected environment mode |
||
35 | */ |
||
36 | protected $mode; |
||
37 | /** |
||
38 | * @var array application configuration array |
||
39 | */ |
||
40 | public $config = []; |
||
41 | |||
42 | /** |
||
43 | * Constructor. Initializes the Environment class. |
||
44 | * |
||
45 | * @param string|array $configDir configuration directory(s) |
||
46 | * @param string $mode override automatically set environment mode |
||
47 | * @throws \Exception |
||
48 | */ |
||
49 | 26 | public function __construct($configDir, $mode = null) |
|
55 | |||
56 | /** |
||
57 | * Set configuration directory(s) where the config files are stored. |
||
58 | * |
||
59 | * @param string|array $configDir configuration directory(s) |
||
60 | * @throws \Exception |
||
61 | */ |
||
62 | 26 | protected function setConfigDir($configDir) |
|
73 | |||
74 | /** |
||
75 | * Set environment mode. |
||
76 | * |
||
77 | * @param string|null $mode environment mode |
||
78 | * @throws \Exception |
||
79 | */ |
||
80 | 24 | protected function setMode($mode) |
|
99 | |||
100 | /** |
||
101 | * Load and merge configuration files into one array. |
||
102 | * |
||
103 | * @return array $config array to be processed by setEnvironment |
||
104 | * @throws \Exception |
||
105 | */ |
||
106 | 22 | protected function getConfig() |
|
142 | |||
143 | /** |
||
144 | * Sets the configuration for the selected mode. |
||
145 | */ |
||
146 | 22 | protected function setEnvironment() |
|
151 | |||
152 | /** |
||
153 | * Merges two or more arrays into one recursively. |
||
154 | * |
||
155 | * If each array has an element with the same string key value, the latter |
||
156 | * will overwrite the former (different from array_merge_recursive). |
||
157 | * Recursive merging will be conducted if both arrays have an element of array |
||
158 | * type and are having the same key. |
||
159 | * For integer-keyed elements, the elements from the latter array will |
||
160 | * be appended to the former array. |
||
161 | * |
||
162 | * params: $a, $b [, array $... ] |
||
163 | * $a array to be merged to |
||
164 | * $b array to be merged from. You can specify additional arrays via third argument, fourth argument etc. |
||
165 | * |
||
166 | * @return array the merged array (the original arrays are not changed.) |
||
167 | */ |
||
168 | 20 | protected static function merge() |
|
191 | |||
192 | /** |
||
193 | * Show current Environment class values. |
||
194 | */ |
||
195 | 2 | public function showDebug() |
|
202 | } |
||
203 |