diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-07-09 19:40:17 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-07-09 19:40:17 +0300 |
commit | f7bfdf58def6aadc922e1632f407d1418269a0d7 (patch) | |
tree | d7a0b2819e6a26c11d40ee0b27267ea827fbb345 /engine/RequestHandler.php |
initial
Diffstat (limited to 'engine/RequestHandler.php')
-rw-r--r-- | engine/RequestHandler.php | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/engine/RequestHandler.php b/engine/RequestHandler.php new file mode 100644 index 0000000..a9dfccd --- /dev/null +++ b/engine/RequestHandler.php @@ -0,0 +1,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']; + } +} |