Request   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 0
loc 73
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A isAjax() 0 4 1
A isSpecial() 0 4 2
A isSecure() 0 6 3
A get() 0 4 1
A post() 0 4 1
A file() 0 4 1
A redirect() 0 4 1
1
<?php
2
3
/**
4
 * @package Cadmium\Framework\Request
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace {
11
12
	abstract class Request {
13
14
		/**
15
		 * Check whether this is an ajax request
16
		 */
17
18
		public static function isAjax() : bool {
19
20
			return (($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') === 'XMLHttpRequest');
21
		}
22
23
		/**
24
		 * Check whether this is a special ajax request
25
		 */
26
27
		public static function isSpecial(string $type) : bool {
28
29
			return (self::isAjax() && ($_SERVER['HTTP_X_SPECIAL_REQUEST'] ?? null) === $type);
30
		}
31
32
		/**
33
		 * Check whether this is a HTTPS request
34
		 */
35
36
		public static function isSecure() : bool {
37
38
			$https = (!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] !== 'off'));
39
40
			return ($https || ($_SERVER['SERVER_PORT'] === '443'));
41
		}
42
43
		/**
44
		 * Get a GET-param value
45
		 *
46
		 * @return string|false : the value or false if the param does not exist
47
		 */
48
49
		public static function get(string $name) {
50
51
			return ($_GET[$name] ?? false);
52
		}
53
54
		/**
55
		 * Get a POST-param value
56
		 *
57
		 * @return string|false : the value or false if the param does not exist
58
		 */
59
60
		public static function post(string $name) {
61
62
			return ($_POST[$name] ?? false);
63
		}
64
65
		/**
66
		 * Get a FILE-param value
67
		 *
68
		 * @return array|false : the array with file info or false if the param does not exist
69
		 */
70
71
		public static function file(string $name) {
72
73
			return ($_FILES[$name] ?? false);
74
		}
75
76
		/**
77
		 * Redirect to a specified url and terminate the script
78
		 */
79
80
		public static function redirect(string $url) {
81
82
			header("Location: " . $url); exit();
83
		}
84
	}
85
}
86