Skip to content

Commit 8e6c8ef

Browse files
committed
docs: describe input class
1 parent 8d92ca1 commit 8e6c8ef

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,78 @@ if ($response->getStatusCode() === 200) {
266266
echo 'Error: ' . $response->getReasonPhrase();
267267
}
268268
```
269+
---
270+
271+
272+
# Input
273+
274+
A simple, secure static helper class for reading and sanitizing `$_GET` and `$_POST` values in PHP. Part of the [MaplePHP HTTP](https://github.com/MaplePHP/Http) library.
275+
276+
### Checking if a key exists
277+
278+
```php
279+
// Check in either $_GET or $_POST
280+
Input::has('name');
281+
282+
// Check only in $_GET
283+
Input::hasGet('page');
284+
285+
// Check only in $_POST
286+
Input::hasPost('email');
287+
```
288+
289+
---
290+
291+
### Reading encoded (safe) values
292+
293+
Values are automatically HTML-encoded to prevent XSS. Returns `null` if the key does not exist.
294+
295+
```php
296+
// From $_GET
297+
$page = Input::get('page');
298+
299+
// From $_POST
300+
$email = Input::post('email');
301+
302+
// From $_GET or $_POST (GET takes priority)
303+
$id = Input::request('id');
304+
305+
// With a fallback default
306+
$page = Input::get('page', '1');
307+
```
308+
309+
---
310+
311+
### Reading raw (unencoded) values
312+
313+
Use raw methods when you need the original unmodified value, or when working with array inputs.
314+
315+
```php
316+
// Scalar raw value
317+
$name = Input::getRaw('name');
318+
319+
// Array input e.g. $_POST['tags'][]
320+
$tags = Input::postRaw('tags');
321+
322+
// With a fallback default
323+
$filters = Input::getRaw('filters', []);
324+
```
325+
326+
> **Note:** Raw values are not sanitized. Make sure to validate or sanitize them before use.
327+
328+
---
329+
330+
### Reading all input
331+
332+
```php
333+
// All raw merged input from $_GET and $_POST (POST takes priority)
334+
$data = Input::all();
335+
336+
// All encoded merged input, including nested arrays
337+
$data = Input::allEncoded();
338+
```
339+
340+
---
269341

270342
## Conclusion
271343

0 commit comments

Comments
 (0)