1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Win\Request; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Manipulador de variáveis globais ($_REQUEST, $_POST, $_GET, etc) |
7
|
|
|
* |
8
|
|
|
* Fornecendo uma camada de segurança maior do que manipulá-las diretamente. |
9
|
|
|
*/ |
10
|
|
|
class Input |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Retorna variável $_POST |
14
|
|
|
* @param string $name |
15
|
|
|
* @param int $filter |
16
|
|
|
* @param mixed $default |
17
|
|
|
* @return mixed |
18
|
|
|
*/ |
19
|
|
|
public static function post($name, $filter = FILTER_SANITIZE_STRING, $default = null) |
20
|
|
|
{ |
21
|
|
|
$post = filter_input(INPUT_POST, $name, $filter); |
22
|
|
|
|
23
|
|
|
return !is_null($post) ? $post : $default; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Retorna variável $_POST em modo array |
28
|
|
|
* @param string $name |
29
|
|
|
* @param int $filter |
30
|
|
|
* @return mixed[] |
31
|
|
|
*/ |
32
|
|
|
public static function postArray($name = null, $filter = FILTER_SANITIZE_STRING) |
33
|
|
|
{ |
34
|
|
|
return (array) filter_input(INPUT_POST, $name, $filter, FILTER_REQUIRE_ARRAY); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Retorna variável $_SERVER |
39
|
|
|
* @param string $name |
40
|
|
|
* @param int $filter |
41
|
|
|
* @return mixed |
42
|
|
|
*/ |
43
|
|
|
public static function server($name, $filter = FILTER_DEFAULT) |
44
|
|
|
{ |
45
|
|
|
$server = (key_exists($name, $_SERVER)) ? $_SERVER[$name] : ''; |
46
|
|
|
|
47
|
|
|
return filter_var($server, $filter); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Retorna variável $_GET |
52
|
|
|
* @param string $name |
53
|
|
|
* @param int $filter |
54
|
|
|
* @param mixed $default |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
|
|
public static function get($name, $filter = FILTER_SANITIZE_STRING, $default = null) |
58
|
|
|
{ |
59
|
|
|
$get = filter_input(INPUT_GET, $name, $filter); |
60
|
|
|
|
61
|
|
|
return !is_null($get) ? $get : $default; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Retorna variável $_FILES |
66
|
|
|
* @param string $name |
67
|
|
|
* @return string[] |
68
|
|
|
*/ |
69
|
|
|
public static function file($name) |
70
|
|
|
{ |
71
|
|
|
if (key_exists($name, $_FILES)) { |
72
|
|
|
return $_FILES[$name]; |
73
|
|
|
} else { |
74
|
|
|
return null; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Retorna o protocolo atual |
80
|
|
|
* @return string 'http'|'https' |
81
|
|
|
*/ |
82
|
|
|
public static function protocol() |
83
|
|
|
{ |
84
|
|
|
$https = Input::server('HTTPS'); |
85
|
|
|
$port = Input::server('SERVER_PORT'); |
86
|
|
|
if (!empty($https) && ('off' !== $https || 443 == $port)) { |
87
|
|
|
return 'https'; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return 'http'; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|