From 6a60e656d31921b29dbfa8e2147360c9e6032644 Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Thu, 9 Nov 2023 16:25:48 +0000 Subject: [PATCH] Fixes the processingf request data from php input --- src/Application/Application.php | 3 ++- src/Http/Client/HttpClient.php | 2 +- src/Http/Request.php | 21 ++++++++++++++++++++- tests/Queue/QueueTest.php | 1 - 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index 4e56b378..50541f31 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -82,10 +82,11 @@ public function __construct(Request $request, Response $response) $this->capsule = Capsule::getInstance(); - $this->capsule->instance('request', $request); $this->capsule->instance('response', $response); + $this->capsule->instance('request', $request); $this->capsule->instance('app', $this); + $this->request->capture(); parent::__construct($request->method(), $request->get('_method')); } diff --git a/src/Http/Client/HttpClient.php b/src/Http/Client/HttpClient.php index 9c94f437..3c65e117 100644 --- a/src/Http/Client/HttpClient.php +++ b/src/Http/Client/HttpClient.php @@ -248,7 +248,7 @@ private function addFields(array $data): void if (count($data) == 0) { return; } - + if ($this->accept_json) { $payload = json_encode($data); } else { diff --git a/src/Http/Request.php b/src/Http/Request.php index 4aec3469..f9f445a0 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -42,13 +42,24 @@ class Request */ private string $id; + /** + * Define the request captured + * + * @var bool + */ + private bool $capture = false; + /** * Request constructor * * @return mixed */ - private function __construct() + public function capture() { + if ($this->capture) { + return; + } + $data = []; $this->id = "req_" . sha1(uniqid() . time()); @@ -76,6 +87,8 @@ private function __construct() $this->input[$key] = $value; } + + $this->capture = true; } /** @@ -348,6 +361,12 @@ public function isAjax(): bool return true; } + $content_type = $this->getHeader("content-type"); + + if ($content_type && str_contains($content_type, "application/json")) { + return true; + } + return false; } diff --git a/tests/Queue/QueueTest.php b/tests/Queue/QueueTest.php index 16f7e80c..6f26248a 100644 --- a/tests/Queue/QueueTest.php +++ b/tests/Queue/QueueTest.php @@ -73,7 +73,6 @@ public function test_instance_of_adapter($connection) } elseif ($connection == "sync") { $this->assertInstanceOf(SyncAdapter::class, $adapter); } - } /**