Browse Source

FetchData: Validate params

pull/26/head
Starbeamrainbowlabs 4 years ago
parent
commit
fc0307a5e0
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 8
      logic/Actions/FetchData.php
  2. 13
      logic/Validator.php

8
logic/Actions/FetchData.php

@ -5,14 +5,18 @@ namespace AirQuality\Actions; @@ -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!");
}
}

13
logic/Validator.php

@ -1,8 +1,6 @@ @@ -1,8 +1,6 @@
<?php
namespace AirQuality;
class Validator {
private $target_data;
private $tests = [];
@ -80,6 +78,17 @@ class Validator { @@ -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…
Cancel
Save