changed PDO to DatabaseConnection

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-24 18:57:47 +01:00
parent 614a56a675
commit c0ac072bb3
1 changed files with 24 additions and 14 deletions

View File

@ -15,7 +15,7 @@ class RequestController
private String $message; private String $message;
/** /**
* @param \App\Controller\DatabaseConnection $databaseConnection * @param DatabaseConnection $databaseConnection
* @param String $requestMethod * @param String $requestMethod
* @param array $uri * @param array $uri
*/ */
@ -31,11 +31,14 @@ class RequestController
*/ */
public function processRequest() 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->status = "404 Not Found";
$this->message = "Endpoint not found."; $this->message = "Endpoint not found.";
} else { } else {
if ($this->checkPassword()) { if ($this->checkPassword()) {
if ($this->uri[2] == "ping") {
$this->status = 'pong';
} else {
try { try {
match ($this->requestMethod) { match ($this->requestMethod) {
'GET' => $this->handleDomainGetRequest(), 'GET' => $this->handleDomainGetRequest(),
@ -49,9 +52,15 @@ class RequestController
} }
} }
} }
}
if (!empty($this->result)) { if (!empty($this->result)) {
echo json_encode($this->result); echo json_encode($this->result);
} else {
if ($this->status == 'pong') {
echo json_encode([
'response' => $this->status
]);
} else { } else {
echo json_encode([ echo json_encode([
'status' => $this->status ?? "Error: No status", 'status' => $this->status ?? "Error: No status",
@ -59,6 +68,7 @@ class RequestController
]); ]);
} }
} }
}
/** /**