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 { class FetchData {
private $settings; private $settings;
private $renderer; private $validator;
public function __construct( public function __construct(
\SBRL\TomlConfig $in_settings) { \SBRL\TomlConfig $in_settings) {
$this->settings = $in_settings; $this->settings = $in_settings;
$this->validator = new \AirQuality\Validator($_GET);
} }
public function handle() { public function handle() {
echo("Testing"); $this->validator->is_datetime("datetime");
$this->validator->run();
echo("Params valid!");
} }
} }

View file

@ -1,8 +1,6 @@
<?php <?php
namespace AirQuality; namespace AirQuality;
class Validator { class Validator {
private $target_data; private $target_data;
private $tests = []; 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) { public function add_test($key, $test, $response_code, $message) {
$new_test = [ $new_test = [
"key" => $key, "key" => $key,