1 | <?php |
||
14 | class Environment |
||
15 | { |
||
16 | /** |
||
17 | * Inherit key that can be used in configConsole |
||
18 | */ |
||
19 | const INHERIT_KEY = 'inherit'; |
||
20 | |||
21 | /** |
||
22 | * @var string name of env var to check |
||
23 | */ |
||
24 | protected $envVar = 'YII_ENVIRONMENT'; |
||
25 | |||
26 | /** |
||
27 | * @var string selected environment mode |
||
28 | */ |
||
29 | protected $mode; |
||
30 | |||
31 | /** |
||
32 | * @var string config dir |
||
33 | */ |
||
34 | protected $configDir; |
||
35 | |||
36 | /** |
||
37 | * @var string path to yii.php |
||
38 | */ |
||
39 | public $yiiPath; |
||
40 | |||
41 | /** |
||
42 | * @var string path to yiic.php |
||
43 | */ |
||
44 | public $yiicPath; |
||
45 | |||
46 | /** |
||
47 | * @var string path to yiit.php |
||
48 | */ |
||
49 | public $yiitPath; |
||
50 | |||
51 | /** |
||
52 | * @var int debug level |
||
53 | */ |
||
54 | public $yiiDebug; |
||
55 | |||
56 | /** |
||
57 | * @var int trace level |
||
58 | */ |
||
59 | public $yiiTraceLevel; |
||
60 | |||
61 | /** |
||
62 | * @var array web config array |
||
63 | */ |
||
64 | public $configWeb; |
||
65 | |||
66 | /** |
||
67 | * @var array console config array |
||
68 | */ |
||
69 | public $configConsole; |
||
70 | |||
71 | /** |
||
72 | * Extend Environment class and merge parent array if you want to modify/extend these |
||
73 | * @return string[] list of valid modes |
||
74 | */ |
||
75 | protected function getValidModes() |
||
84 | |||
85 | /** |
||
86 | * Initilizes the Environment class with the given mode |
||
87 | * @param string $mode used to override automatically setting mode |
||
88 | * @param string $configDir override default configDir |
||
89 | */ |
||
90 | public function __construct($mode = null, $configDir = null) |
||
96 | |||
97 | /** |
||
98 | * Set config dir. |
||
99 | * @param string $configDir |
||
100 | */ |
||
101 | protected function setConfigDir($configDir) |
||
109 | |||
110 | /** |
||
111 | * Set environment mode, if valid mode can be determined. |
||
112 | * @param string $mode if left empty, determine automatically |
||
113 | */ |
||
114 | protected function setMode($mode = null) |
||
129 | |||
130 | /** |
||
131 | * Determine current environment mode depending on environment variable. |
||
132 | * Also checks if there is a mode file that might override this environment. |
||
133 | * Override this function if you want to implement your own method. |
||
134 | * @return string mode |
||
135 | */ |
||
136 | protected function determineMode() |
||
150 | |||
151 | /** |
||
152 | * @return string mode file path |
||
153 | */ |
||
154 | protected function getModeFilePath() |
||
158 | |||
159 | /** |
||
160 | * Load and merge config files into one array. |
||
161 | * @return array $config array to be processed by setEnvironment. |
||
162 | */ |
||
163 | protected function getConfig() |
||
192 | |||
193 | /** |
||
194 | * Sets the environment and configuration for the selected mode. |
||
195 | */ |
||
196 | protected function setEnvironment() |
||
220 | |||
221 | /** |
||
222 | * Show current Environment class values |
||
223 | */ |
||
224 | public function showDebug() |
||
231 | |||
232 | /** |
||
233 | * Merges two arrays into one recursively. |
||
234 | * @param array $a array to be merged to |
||
235 | * @param array $b array to be merged from |
||
236 | * @return array the merged array (the original arrays are not changed.) |
||
237 | * |
||
238 | * Taken from Yii's CMap::mergeArray, since php does not supply a native |
||
239 | * function that produces the required result. |
||
240 | * @see http://www.yiiframework.com/doc/api/1.1/CMap#mergeArray-detail |
||
241 | */ |
||
242 | protected static function mergeArray($a, $b) |
||
255 | |||
256 | /** |
||
257 | * Loop through console config array, replacing values called 'inherit' by values from $this->configWeb |
||
258 | * @param mixed $array target array |
||
259 | * @param string[] $path array that keeps track of current path |
||
260 | */ |
||
261 | private function processInherits(&$array, $path = array()) |
||
273 | |||
274 | /** |
||
275 | * Walk $array through $path until the end, and return value |
||
276 | * @param array $array target |
||
277 | * @param array $path path array, from deep key to shallow key |
||
278 | * @return mixed |
||
279 | */ |
||
280 | private function getValueFromArray(&$array, $path) |
||
288 | } |
||
289 |