From c0ac072bb3fa268809835678144c452ac64e1bd3 Mon Sep 17 00:00:00 2001 From: tracer Date: Mon, 24 Jan 2022 18:57:47 +0100 Subject: [PATCH] changed PDO to DatabaseConnection Signed-off-by: tracer --- src/Controller/RequestController.php | 38 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Controller/RequestController.php b/src/Controller/RequestController.php index c4d9785..4f03270 100644 --- a/src/Controller/RequestController.php +++ b/src/Controller/RequestController.php @@ -15,7 +15,7 @@ class RequestController private String $message; /** - * @param \App\Controller\DatabaseConnection $databaseConnection + * @param DatabaseConnection $databaseConnection * @param String $requestMethod * @param array $uri */ @@ -31,21 +31,25 @@ class RequestController */ public function processRequest() { - if (empty($this->uri[2]) || $this->uri[2] != 'domains') { + if (empty($this->uri[2]) || !(($this->uri[2] == 'domains') || $this->uri[2] == 'ping')) { $this->status = "404 Not Found"; $this->message = "Endpoint not found."; } else { if ($this->checkPassword()) { - try { - match ($this->requestMethod) { - 'GET' => $this->handleDomainGetRequest(), - 'POST' => $this->handleDomainPostRequest(), - 'PUT' => $this->handleDomainPutRequest(), - 'DELETE' => $this->handleDomainDeleteRequest() - }; - } catch(UnhandledMatchError) { + if ($this->uri[2] == "ping") { + $this->status = 'pong'; + } else { + try { + match ($this->requestMethod) { + 'GET' => $this->handleDomainGetRequest(), + 'POST' => $this->handleDomainPostRequest(), + 'PUT' => $this->handleDomainPutRequest(), + 'DELETE' => $this->handleDomainDeleteRequest() + }; + } catch(UnhandledMatchError) { $this->status = "400 Bad Request"; $this->message = "unknown request method: $this->requestMethod"; + } } } } @@ -53,10 +57,16 @@ class RequestController if (!empty($this->result)) { echo json_encode($this->result); } else { - echo json_encode([ - 'status' => $this->status ?? "Error: No status", - 'message' => $this->message ?? "Error: No message." - ]); + if ($this->status == 'pong') { + echo json_encode([ + 'response' => $this->status + ]); + } else { + echo json_encode([ + 'status' => $this->status ?? "Error: No status", + 'message' => $this->message ?? "Error: No message." + ]); + } } }