blob: a9dfccdeae9413d813734e23b03519b60926f817 (
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
<?php
class RequestHandler {
public function __construct(
protected Skin $skin,
protected LangData $lang,
protected array $routerInput
) {}
public function beforeDispatch(): ?Response {
return null;
}
public function get(): Response {
throw new NotImplementedException();
}
public function post(): Response {
throw new NotImplementedException();
}
public function input(string $input): array {
$input = preg_split('/,\s+?/', $input, -1, PREG_SPLIT_NO_EMPTY);
$ret = [];
foreach ($input as $var) {
if (($pos = strpos($var, ':')) !== false) {
$type = InputType::from(substr($var, 0, $pos));
$name = trim(substr($var, $pos+1));
} else {
$type = InputType::STRING;
$name = $var;
}
$value = $this->routerInput[$name] ?? $_REQUEST[$name] ?? '';
switch ($type) {
case InputType::INT:
$value = (int)$value;
break;
case InputType::FLOAT:
$value = (float)$value;
break;
case InputType::BOOL:
$value = (bool)$value;
break;
}
$ret[] = $value;
}
return $ret;
}
protected function isRetina(): bool {
return isset($_COOKIE['is_retina']) && $_COOKIE['is_retina'];
}
}
|