From 45abea53014cb4a380e87672109a1f0e68f0b185 Mon Sep 17 00:00:00 2001 From: kj Date: Thu, 20 Feb 2025 06:28:03 -0300 Subject: [PATCH] Add delete request params. --- src/Libs/Request.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Libs/Request.php b/src/Libs/Request.php index 4d2e53d..eb7a938 100644 --- a/src/Libs/Request.php +++ b/src/Libs/Request.php @@ -17,6 +17,7 @@ class Request extends Neuron { public Neuron $post; public Neuron $put; public Neuron $patch; + public Neuron $delete; public Neuron $json; public Neuron $params; public string $path; @@ -35,6 +36,7 @@ class Request extends Neuron { $this->post = new Neuron($_POST); $this->put = new Neuron(); $this->patch = new Neuron(); + $this->delete = new Neuron(); $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : ''; if ($contentType === "application/json") @@ -43,7 +45,7 @@ class Request extends Neuron { ); else { $this->json = new Neuron(); - if (in_array($_SERVER['REQUEST_METHOD'], ['PUT', 'PATCH'])) { + if (in_array($_SERVER['REQUEST_METHOD'], ['PUT', 'PATCH', 'DELETE'])) { parse_str(file_get_contents("php://input"), $input_vars); $this->{strtolower($_SERVER['REQUEST_METHOD'])} = new Neuron($input_vars); } @@ -73,8 +75,8 @@ class Request extends Neuron { public function validate(): bool { $actual = match($_SERVER['REQUEST_METHOD']) { - 'GET', 'DELETE' => $this->get, - default => $this->{strtolower($_SERVER['REQUEST_METHOD'])} + 'POST', 'PUT', 'PATCH', 'DELETE' => $this->{strtolower($_SERVER['REQUEST_METHOD'])}, + default => $this->get }; if (Validator::validateList(static::paramRules(), $this->params) &&