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/Application/ApplicationTest.php b/tests/Application/ApplicationTest.php index 7d6a2e3d..1f88526b 100644 --- a/tests/Application/ApplicationTest.php +++ b/tests/Application/ApplicationTest.php @@ -29,6 +29,7 @@ public function test_instance_of_application() $request = Mockery::mock(Request::class); $request->allows()->method()->andReturns("GET"); + $request->allows()->capture()->andReturns(null); $request->allows()->get("_method")->andReturns(""); $app = Application::make($request, $response); @@ -45,6 +46,7 @@ public function test_one_time_application_boot() $request = Mockery::mock(Request::class); $request->allows()->method()->andReturns("GET"); + $request->allows()->capture()->andReturns(null); $request->allows()->get("_method")->andReturns(""); $app = Application::make($request, $response); @@ -68,6 +70,7 @@ public function test_send_application_with_404_status() // Request mock method $request->allows()->method()->andReturns("GET"); + $request->allows()->capture()->andReturns(null); $request->allows()->path()->andReturns("/"); $request->allows()->get("_method")->andReturns(""); @@ -96,6 +99,7 @@ public function test_send_application_with_matched_route() // Request mock method $request->allows()->method()->andReturns("GET"); + $request->allows()->capture()->andReturns(null); $request->allows()->path()->andReturns("/"); $request->allows()->get("_method")->andReturns(""); @@ -128,6 +132,7 @@ public function test_send_application_with_no_matched_route() // Request mock method $request->allows()->method()->andReturns("GET"); + $request->allows()->capture()->andReturns(null); $request->allows()->path()->andReturns("/name"); $request->allows()->get("_method")->andReturns(""); 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); } - } /**