mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-11-22 06:23:01 +00:00
FetchData: Validate params
This commit is contained in:
parent
4939238861
commit
fc0307a5e0
2 changed files with 17 additions and 4 deletions
|
@ -5,14 +5,18 @@ namespace AirQuality\Actions;
|
|||
|
||||
class FetchData {
|
||||
private $settings;
|
||||
private $renderer;
|
||||
private $validator;
|
||||
|
||||
public function __construct(
|
||||
\SBRL\TomlConfig $in_settings) {
|
||||
$this->settings = $in_settings;
|
||||
$this->validator = new \AirQuality\Validator($_GET);
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
echo("Testing");
|
||||
$this->validator->is_datetime("datetime");
|
||||
$this->validator->run();
|
||||
|
||||
echo("Params valid!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
<?php
|
||||
namespace AirQuality;
|
||||
|
||||
|
||||
|
||||
class Validator {
|
||||
private $target_data;
|
||||
private $tests = [];
|
||||
|
@ -80,6 +78,17 @@ class Validator {
|
|||
);
|
||||
}
|
||||
|
||||
public function is_datetime($key) {
|
||||
$this->add_test(
|
||||
$key,
|
||||
function($data) {
|
||||
return strtotime($data) !== false;
|
||||
},
|
||||
400,
|
||||
"The datetime provided in the '$key' parameter is invalid."
|
||||
);
|
||||
}
|
||||
|
||||
public function add_test($key, $test, $response_code, $message) {
|
||||
$new_test = [
|
||||
"key" => $key,
|
||||
|
|
Loading…
Reference in a new issue