-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetenv.php
executable file
·96 lines (81 loc) · 2.34 KB
/
getenv.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace PMVC\PlugIn\getenv;
use PMVC\PlugIn\get\GetInterface;
use PMVC\PlugIn;
${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\getenv';
\PMVC\initPlugin(['get' => null], true);
/**
* @parameters bool isDev
*/
class getenv extends PlugIn implements GetInterface
{
public function init()
{
$this['SITE'] = function (&$isCache) {
$isCache = true;
$site = $this->getDefault(
'SITE',
basename(\PMVC\callPlugin('controller', 'getAppsParent') || '')
);
return $site;
};
$this['UTM'] = function (&$isCache, $key) {
$isCache = true;
return $this->utm($key);
};
$this['CDN'] = function (&$isCache, $key) {
$isCache = true;
return $this->cdn($key);
};
$this['COUNTRY'] = function (&$isCache, $key) {
$isCache = true;
return $this->country($key);
};
$this['HOST_ARRAY'] = function (&$isCache, $key) {
$isCache = true;
$host = $this->get('HTTP_HOST');
return explode('.', $host);
};
$this['UNIQUE_ID'] = function (&$isCache, $key) {
$isCache = true;
$unique = $this->getDefault('UNIQUE_ID');
if (empty($unique)) {
$unique = $this->getDefault('HTTP_X_UNIQUE_ID');
}
return $unique;
};
}
public function get($k)
{
$reqKey = '--' . $k;
$request = $this->request();
if ($this['isDev'] && isset($request[$reqKey])) {
return $_REQUEST[$reqKey];
} elseif (isset($this[$k])) {
if (!is_callable($this[$k])) {
return $this[$k];
}
$isCache = false;
$v = $this[$k]($isCache, $k, $this);
if ($isCache) {
$this[$k] = $v;
}
return $v;
} else {
return $this->getDefault($k);
}
}
public function getDefault($k, $default = null)
{
return \PMVC\get($_SERVER, $k, $default);
}
public function has($k)
{
return isset($_SERVER[$k]) || isset($this[$k]);
}
public function request()
{
$creq = \PMVC\callPlugin('controller', 'getRequest');
return $creq ? $creq : $_REQUEST;
}
}