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 = 'YII_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 string path to Yii.php |
||
39 | */ |
||
40 | public $yiiPath; |
||
41 | /** |
||
42 | * @var boolean debug mode or not |
||
43 | */ |
||
44 | public $yiiDebug; |
||
45 | /** |
||
46 | * @var string defines in which environment the application is running |
||
47 | */ |
||
48 | public $yiiEnv; |
||
49 | /** |
||
50 | * @var array register path aliases |
||
51 | */ |
||
52 | public $aliases = []; |
||
53 | /** |
||
54 | * @var array merge class map used by the Yii autoloading mechanism |
||
55 | */ |
||
56 | public $classMap = []; |
||
57 | /** |
||
58 | * @var array web application configuration array |
||
59 | */ |
||
60 | public $web = []; |
||
61 | /** |
||
62 | * @var array console application configuration array |
||
63 | */ |
||
64 | public $console = []; |
||
65 | |||
66 | /** |
||
67 | * Constructor. Initializes the Environment class. |
||
68 | * |
||
69 | * @param string|array $configDir configuration directory(s) |
||
70 | * @param string $mode override automatically set environment mode |
||
71 | * @throws \Exception |
||
72 | */ |
||
73 | 28 | public function __construct($configDir, $mode = null) |
|
79 | |||
80 | /** |
||
81 | * Set configuration directory(s) where the config files are stored. |
||
82 | * |
||
83 | * @param string|array $configDir configuration directory(s) |
||
84 | * @throws \Exception |
||
85 | */ |
||
86 | 28 | protected function setConfigDir($configDir) |
|
97 | |||
98 | /** |
||
99 | * Set environment mode. |
||
100 | * |
||
101 | * @param string|null $mode environment mode |
||
102 | * @throws \Exception |
||
103 | */ |
||
104 | 26 | protected function setMode($mode) |
|
123 | |||
124 | /** |
||
125 | * Load and merge configuration files into one array. |
||
126 | * |
||
127 | * @return array $config array to be processed by setEnvironment |
||
128 | * @throws \Exception |
||
129 | */ |
||
130 | 24 | protected function getConfig() |
|
166 | |||
167 | /** |
||
168 | * Sets the environment and configuration for the selected mode. |
||
169 | * |
||
170 | * @throws \Exception |
||
171 | */ |
||
172 | 24 | protected function setEnvironment() |
|
190 | |||
191 | /** |
||
192 | * Merges two arrays into one recursively. |
||
193 | * |
||
194 | * @param array $a array to be merged to |
||
195 | * @param array $b array to be merged from. |
||
196 | * @return array the merged array (the original arrays are not changed.) |
||
197 | */ |
||
198 | 22 | protected static function merge($a, $b) |
|
202 | |||
203 | /** |
||
204 | * Defines Yii constants, includes base Yii class, sets aliases and merges class map. |
||
205 | */ |
||
206 | 2 | public function setup() |
|
235 | |||
236 | /** |
||
237 | * Show current Environment class values. |
||
238 | */ |
||
239 | 2 | public function showDebug() |
|
246 | } |
||
247 |