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,21 +31,25 @@ 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()) {
try { if ($this->uri[2] == "ping") {
match ($this->requestMethod) { $this->status = 'pong';
'GET' => $this->handleDomainGetRequest(), } else {
'POST' => $this->handleDomainPostRequest(), try {
'PUT' => $this->handleDomainPutRequest(), match ($this->requestMethod) {
'DELETE' => $this->handleDomainDeleteRequest() 'GET' => $this->handleDomainGetRequest(),
}; 'POST' => $this->handleDomainPostRequest(),
} catch(UnhandledMatchError) { 'PUT' => $this->handleDomainPutRequest(),
'DELETE' => $this->handleDomainDeleteRequest()
};
} catch(UnhandledMatchError) {
$this->status = "400 Bad Request"; $this->status = "400 Bad Request";
$this->message = "unknown request method: $this->requestMethod"; $this->message = "unknown request method: $this->requestMethod";
}
} }
} }
} }
@ -53,10 +57,16 @@ class RequestController
if (!empty($this->result)) { if (!empty($this->result)) {
echo json_encode($this->result); echo json_encode($this->result);
} else { } else {
echo json_encode([ if ($this->status == 'pong') {
'status' => $this->status ?? "Error: No status", echo json_encode([
'message' => $this->message ?? "Error: No message." 'response' => $this->status
]); ]);
} else {
echo json_encode([
'status' => $this->status ?? "Error: No status",
'message' => $this->message ?? "Error: No message."
]);
}
} }
} }