Compare commits

..

2 Commits

Author SHA1 Message Date
KJ
daf7250882 Catch and verify put and patch input values. 2024-08-13 10:22:44 -04:00
KJ
05cd83fd10 Remove unused variable. 2024-07-31 03:29:49 -04:00
2 changed files with 15 additions and 8 deletions

View File

@ -819,8 +819,6 @@ class Model {
$in = array_keys((new $className())->getVars());
}
$db = static::db();
$search = static::bindValue($search);
$where = [];

View File

@ -15,6 +15,8 @@ namespace Libs;
class Request extends Neuron {
public Neuron $get;
public Neuron $post;
public Neuron $put;
public Neuron $patch;
public Neuron $json;
public Neuron $params;
public string $path;
@ -31,14 +33,21 @@ class Request extends Neuron {
$this->path = Router::currentPath();
$this->get = new Neuron($_GET);
$this->post = new Neuron($_POST);
$this->put = new Neuron();
$this->patch = new Neuron();
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if ($contentType === "application/json")
$this->json = new Neuron(
(object) json_decode(trim(file_get_contents("php://input")), false)
);
else
else {
$this->json = new Neuron();
if (in_array($_SERVER['REQUEST_METHOD'], ['PUT', 'PATCH'])) {
parse_str(file_get_contents("php://input"), $input_vars);
$this->{strtolower($_SERVER['REQUEST_METHOD'])} = new Neuron($input_vars);
}
}
$this->params = new Neuron();
}
@ -50,10 +59,10 @@ class Request extends Neuron {
*/
public function validate(): mixed
{
if ($_SERVER['REQUEST_METHOD'] == 'GET')
$actual = $this->get;
else
$actual = $this->post;
$actual = match($_SERVER['REQUEST_METHOD']) {
'GET', 'DELETE' => $this->get,
default => $this->{strtolower($_SERVER['REQUEST_METHOD'])}
};
if (Validator::validateList(static::paramRules(), $this->params) &&
Validator::validateList(static::getRules(), $this->get ) &&