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;
/**
* @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."
]);
}
}
}