forked from c93614/yii-env-detect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvironment.php
57 lines (50 loc) · 1.34 KB
/
Environment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
class Environment {
const DEVEL = 0;
const TEST = 1;
const STAGE = 2;
const PRODUCTION = 3;
public static $env;
public static $debug;
public static $trace;
public static $config;
protected static $dict = array(
array( /* DEVEL */
'debug' => true,
'trace' => 3,
'config' => 'devel.php',
),
array( /* TEST */
'debug' => true,
'trace' => 3,
'config' => 'test.php',
),
array( /* STAGE */
'debug' => true,
'trace' => 3,
'config' => 'stage.php',
),
array( /* PRODUCTION */
'debug' => false,
'trace' => 3,
'config' => 'main.php'
),
);
public static function detect() {
if (self::$env == null) {
// detect
self::$env = self::PRODUCTION;
if (isset($_SERVER['APPLICATION_ENV'])) {
$env = strtoupper($_SERVER['APPLICATION_ENV']);
if (defined("self::$env")) {
self::$env = constant("self::$env");
}
}
foreach(self::$dict[self::$env] as $property => $value) {
self::$$property = $value;
}
// clean
self::$dict = null;
}
}
}