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 {
|
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!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue