1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DBSeller\Legacy\PHP53; |
4
|
|
|
|
5
|
|
|
class Emulate { |
6
|
|
|
|
7
|
|
|
private static $egpcs = array( |
8
|
|
|
'ENV', 'GET', 'POST', 'COOKIE', 'SERVER', 'SESSION', 'FILES' |
9
|
|
|
); |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Emula a variavel de ambiente $_ENV |
13
|
|
|
* |
14
|
|
|
* @return boolean |
15
|
|
|
*/ |
16
|
|
|
public static function env() { |
|
|
|
|
17
|
|
|
|
18
|
|
|
$GLOBALS['_ENV'] = array(); |
19
|
|
|
$GLOBALS['_ENV']['PATH_INFO'] = getenv('PATH_INFO'); |
20
|
|
|
$GLOBALS['_ENV']['HTTP_USER_AGENT'] = getenv('HTTP_USER_AGENT'); |
21
|
|
|
return true; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Emula: register_long_arrays = On |
26
|
|
|
* |
27
|
|
|
* @return boolean |
28
|
|
|
*/ |
29
|
|
|
public static function registerLongArrays() { |
30
|
|
|
|
31
|
|
|
foreach (self::$egpcs as $name) { |
32
|
|
|
$GLOBALS["HTTP_{$name}_VARS"] =& $GLOBALS["_$name"]; |
33
|
|
|
} |
34
|
|
|
return true; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Emula: register_globals = On |
39
|
|
|
* |
40
|
|
|
* @return boolean |
41
|
|
|
*/ |
42
|
|
|
public static function registerGlobals() { |
43
|
|
|
|
44
|
|
|
foreach (self::$egpcs as $name) { |
45
|
|
|
|
46
|
|
|
if (!isset($GLOBALS["_$name"])) { |
47
|
|
|
continue; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
foreach($GLOBALS['_'.$name] as $key => & $value) { |
51
|
|
|
$GLOBALS[$key] = $value; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
reset($GLOBALS["_$name"]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Emula: magic_quotes_gpc = On|Off |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public static function magicQuotesGPCR($directive = 'On') { |
66
|
|
|
|
67
|
|
|
$active = true; |
68
|
|
|
|
69
|
|
|
if (strtolower($directive) == 'off' || (is_bool($directive) && $directive === false)) { |
70
|
|
|
$active = false; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$handler = function(&$value) use($active) { |
74
|
|
|
$value = $active ? addslashes($value) : stripslashes($value); |
75
|
|
|
}; |
76
|
|
|
|
77
|
|
|
array_walk_recursive($_GET, $handler); |
78
|
|
|
array_walk_recursive($_POST, $handler); |
79
|
|
|
array_walk_recursive($_COOKIE, $handler); |
80
|
|
|
array_walk_recursive($_REQUEST, $handler); |
81
|
|
|
|
82
|
|
|
reset($_GET); |
83
|
|
|
reset($_POST); |
84
|
|
|
reset($_COOKIE); |
85
|
|
|
reset($_REQUEST); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Emula o comportamento do session_register |
90
|
|
|
* @static |
91
|
|
|
* @link http://php.net/manual/pt_BR/function.session-register.php |
92
|
|
|
*/ |
93
|
|
|
public static function sessionRegister() { |
|
|
|
|
94
|
|
|
|
95
|
|
|
$args = func_get_args(); |
96
|
|
|
foreach ($args as $key){ |
97
|
|
|
|
98
|
|
|
$_SESSION[$key]= isset($GLOBALS[$key]) ? $GLOBALS[$key] : null; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Emula o comportamento da função session_is_registered |
104
|
|
|
* |
105
|
|
|
* @link http://php.net/manual/pt_BR/function.session-is-registered.php |
106
|
|
|
* @static |
107
|
|
|
* @param mixed $key |
108
|
|
|
*/ |
109
|
|
|
public static function sessionIsRegistered($key) { |
110
|
|
|
return array_key_exists($key, $_SESSION); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Emula o comportamento da função sesion_unregister |
115
|
|
|
* |
116
|
|
|
* @link http://php.net/manual/pt_BR/function.session-unregister.php |
117
|
|
|
* @static |
118
|
|
|
* @param mixed $key |
119
|
|
|
*/ |
120
|
|
|
public static function sessionUnregister($key) { |
|
|
|
|
121
|
|
|
unset($_SESSION[$key]); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: