Add delete request params.

This commit is contained in:
kj 2025-02-20 06:28:03 -03:00
parent d441f001ec
commit 45abea5301

View File

@ -17,6 +17,7 @@ class Request extends Neuron {
public Neuron $post; public Neuron $post;
public Neuron $put; public Neuron $put;
public Neuron $patch; public Neuron $patch;
public Neuron $delete;
public Neuron $json; public Neuron $json;
public Neuron $params; public Neuron $params;
public string $path; public string $path;
@ -35,6 +36,7 @@ class Request extends Neuron {
$this->post = new Neuron($_POST); $this->post = new Neuron($_POST);
$this->put = new Neuron(); $this->put = new Neuron();
$this->patch = new Neuron(); $this->patch = new Neuron();
$this->delete = new Neuron();
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : ''; $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if ($contentType === "application/json") if ($contentType === "application/json")
@ -43,7 +45,7 @@ class Request extends Neuron {
); );
else { else {
$this->json = new Neuron(); $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); parse_str(file_get_contents("php://input"), $input_vars);
$this->{strtolower($_SERVER['REQUEST_METHOD'])} = new Neuron($input_vars); $this->{strtolower($_SERVER['REQUEST_METHOD'])} = new Neuron($input_vars);
} }
@ -73,8 +75,8 @@ class Request extends Neuron {
public function validate(): bool public function validate(): bool
{ {
$actual = match($_SERVER['REQUEST_METHOD']) { $actual = match($_SERVER['REQUEST_METHOD']) {
'GET', 'DELETE' => $this->get, 'POST', 'PUT', 'PATCH', 'DELETE' => $this->{strtolower($_SERVER['REQUEST_METHOD'])},
default => $this->{strtolower($_SERVER['REQUEST_METHOD'])} default => $this->get
}; };
if (Validator::validateList(static::paramRules(), $this->params) && if (Validator::validateList(static::paramRules(), $this->params) &&