summaryrefslogtreecommitdiff
path: root/web/_model/request.php
blob: 4cce07a9fc4cccf484e4ee505d29f02d65972808 (plain)
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
<?php /* Copyright (c) 2024 Freya Murphy */
class Request_model extends Model {

	function __construct($load) {
		parent::__construct($load);
	}

	/**
	 * Loads a string from the GET request
	 * @param string $key - the name for the query param
	 * @param string $default - the default value if not exists
	 */
	public function get_str($key, $default = NULL): string | NULL {
		if (!array_key_exists($key, $_GET)) {
			return $default;
		} else {
			return $_GET[$key];
		}
	}

	/**
	 * Loads a number from the GET request
	 * @param string $key - the name for the query param
	 * @param int $default - the default value if not exists
	 */
	public function get_int($key, $default = NULL): int | NULL {
		if (!array_key_exists($key, $_GET)) {
			return $default;
		} else {
			$val = $_GET[$key];
			$val = intval($val);
			if ($val < 0) {
				return 0;
			} else {
				return $val;
			}
		}
	}

}