1 | <?php |
||
37 | class Input |
||
38 | { |
||
39 | /** |
||
40 | * Constant for POST request. |
||
41 | */ |
||
42 | const POST = INPUT_POST; |
||
43 | |||
44 | /** |
||
45 | * Constant for GET request. |
||
46 | */ |
||
47 | const GET = INPUT_GET; |
||
48 | |||
49 | /** |
||
50 | * Constant for INPUT request. |
||
51 | */ |
||
52 | const REQUEST = INPUT_REQUEST; |
||
53 | |||
54 | const REQUEST_DECODER_INTERNAL = "Input::decodeInternal"; |
||
55 | |||
56 | const REQUEST_DECODER_PHP = "Input::decodePhp"; |
||
57 | |||
58 | private static $decoder = self::REQUEST_DECODER_PHP; |
||
59 | |||
60 | /** |
||
61 | * Cache or arrays which hold decoded query strings. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | private static $arrays = []; |
||
66 | |||
67 | // /** |
||
68 | // * Decodes and returns the value of a given item in an HTTP query. |
||
69 | // * |
||
70 | // * Although PHP decodes query strings automatically, it converts periods to underscores. This method makes it |
||
71 | // * possible to decode query strings that contain periods. |
||
72 | // * Based on code from http://stackoverflow.com/a/14432765 |
||
73 | // * |
||
74 | // * @param string $method The HTTP method of the query (GET, POST ...) |
||
75 | // * @param string $key The key of the item in the query to retrieve. |
||
76 | // * @return mixed |
||
77 | // */ |
||
78 | // private static function decode(string $method, string $key = null) |
||
79 | // { |
||
80 | // if(!isset(self::$arrays[$method])) { |
||
81 | // $query = $method == self::GET |
||
82 | // ? filter_input(INPUT_SERVER, 'QUERY_STRING') |
||
83 | // : file_get_contents('php://input'); |
||
84 | // $query = preg_replace_callback('/(^|(?<=&))[^=[&]+/', |
||
85 | // function($match) { |
||
86 | // return bin2hex($match[0]); |
||
87 | // }, $query); |
||
88 | // parse_str($query, $data); |
||
89 | // self::$arrays[$method] = array_combine(array_map('hex2bin', array_keys($data)), $data); |
||
90 | // } |
||
91 | // return $key ? (self::$arrays[$method][$key] ?? null) : (self::$arrays[$method] ?? null); |
||
92 | // } |
||
93 | |||
94 | /** |
||
95 | * Does the actual work of calling either the filter_input of |
||
96 | * filter_input_array. Calls the filter_input when a data key is provided |
||
97 | * and callse the filte_input_array when a data key is absent. |
||
98 | * |
||
99 | * @param string $input Input type |
||
100 | * @param string $key The data key |
||
101 | * @return string|array The value. |
||
102 | */ |
||
103 | private static function getVariable(string $input, string $key = null) |
||
120 | |||
121 | /** |
||
122 | * Retrieves GET request variables. |
||
123 | * |
||
124 | * @param string $key |
||
125 | * @return string|array |
||
126 | */ |
||
127 | public static function get(string $key = null) |
||
131 | |||
132 | /** |
||
133 | * Retrieves post request variables. |
||
134 | * |
||
135 | * @param string $key |
||
136 | * @return string|array |
||
137 | */ |
||
138 | public static function post(string $key = null) |
||
142 | |||
143 | /** |
||
144 | * Retrieves server variables. |
||
145 | * |
||
146 | * @param string $key |
||
147 | * @return string|array |
||
148 | */ |
||
149 | public static function server(string $key = null) |
||
153 | |||
154 | /** |
||
155 | * Retrieves cookie variables. |
||
156 | * |
||
157 | * @param string $key |
||
158 | * @return string|array |
||
159 | */ |
||
160 | public static function cookie(string $key = null) |
||
164 | |||
165 | /** |
||
166 | * Checks if a particular key exists in a given request query. |
||
167 | * |
||
168 | * @param string $input |
||
169 | * @param string $key |
||
170 | * @return bool |
||
171 | */ |
||
172 | public static function exists(string $input, string $key) : bool |
||
176 | |||
177 | /** |
||
178 | * Retrieves uploaded files as instances of UploadedFile or an array of UploadedFile if multiples exist. |
||
179 | * |
||
180 | * @param string $key |
||
181 | * @return array|filesystem\UploadedFile|null |
||
182 | */ |
||
183 | public static function files(string $key = null) |
||
194 | |||
195 | private static function getFileObjects($key) |
||
210 | |||
211 | } |
||
212 |