FetchData: Validate params

This commit is contained in:
Starbeamrainbowlabs 2019-01-14 20:41:25 +00:00
parent 4939238861
commit fc0307a5e0
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 17 additions and 4 deletions

View file

@ -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!");
}
}

View file

@ -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,