summaryrefslogtreecommitdiffstats
path: root/inc/request.inc.php
blob: f46210afde31c1bad48b184028093ad7f3ce0712 (plain) (blame)
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
<?php

/**
 * Wrapper for getting fields from the request (GET, POST, ...)
 */
class Request
{

	/**
	 *
	 * @param string $key Key of field to get from $_GET
	 * @param string $default Value to return if $_GET does not contain $key
	 * @param string $type if the parameter exists, cast it to given type
	 * @return mixed Field from $_GET, or $default if not set
	 */
	public static function get($key, $default = false, $type = false)
	{
		if (!isset($_GET[$key])) return $default;
		if ($type !== false) settype($_GET[$key], $type);
		return $_GET[$key];
	}
	
	/**
	 * 
	 * @param string $key Key of field to get from $_POST
	 * @param string $default Value to return if $_POST does not contain $key
	 * @return mixed Field from $_POST, or $default if not set
	 */
	public static function post($key, $default = false, $type = false)
	{
		if (!isset($_POST[$key])) return $default;
		if ($type !== false) settype($_POST[$key], $type);
		return $_POST[$key];
	}
	
	/**
	 * 
	 * @param string $key Key of field to get from $_REQUEST
	 * @param string $default Value to return if $_REQUEST does not contain $key
	 * @return mixed Field from $_REQUEST, or $default if not set
	 */
	public static function any($key, $default = false, $type = false)
	{
		if (!isset($_REQUEST[$key])) return $default;
		if ($type !== false) settype($_REQUEST[$key], $type);
		return $_REQUEST[$key];
	}
	
}