From 4c7bde1400820f36caf8b2a5374007384c3018f3 Mon Sep 17 00:00:00 2001 From: winter Date: Mon, 9 Dec 2024 21:31:54 +0000 Subject: rename to Digitigrade / PawPub :3 --- Digitigrade/HttpResponseStatus/BadRequest.php | 18 +++++++++++++++++ .../HttpResponseStatus/InternalServerError.php | 23 ++++++++++++++++++++++ Digitigrade/HttpResponseStatus/NoHandlerFound.php | 18 +++++++++++++++++ Digitigrade/HttpResponseStatus/NotFound.php | 18 +++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 Digitigrade/HttpResponseStatus/BadRequest.php create mode 100644 Digitigrade/HttpResponseStatus/InternalServerError.php create mode 100644 Digitigrade/HttpResponseStatus/NoHandlerFound.php create mode 100644 Digitigrade/HttpResponseStatus/NotFound.php (limited to 'Digitigrade/HttpResponseStatus') diff --git a/Digitigrade/HttpResponseStatus/BadRequest.php b/Digitigrade/HttpResponseStatus/BadRequest.php new file mode 100644 index 0000000..ba7ce65 --- /dev/null +++ b/Digitigrade/HttpResponseStatus/BadRequest.php @@ -0,0 +1,18 @@ +message = $reason ?? 'Request does not conform to expectations'; + } + + public function httpCode(): int { + return 400; + } + + public function httpReason(): string { + return "Bad Request"; + } +} \ No newline at end of file diff --git a/Digitigrade/HttpResponseStatus/InternalServerError.php b/Digitigrade/HttpResponseStatus/InternalServerError.php new file mode 100644 index 0000000..237c526 --- /dev/null +++ b/Digitigrade/HttpResponseStatus/InternalServerError.php @@ -0,0 +1,23 @@ +message = $reason::class . ': ' . $reason->getMessage(); + if (isset($context)) { + $this->message .= " [$context]"; + } + if (GlobalConfig::getInstance()->shouldReportTraces()) { + $this->message .= "\n" . $reason->getTraceAsString(); + } + } + public function httpCode(): int { + return 500; + } + public function httpReason(): string { + return "Internal Server Error"; + } +} \ No newline at end of file diff --git a/Digitigrade/HttpResponseStatus/NoHandlerFound.php b/Digitigrade/HttpResponseStatus/NoHandlerFound.php new file mode 100644 index 0000000..871b873 --- /dev/null +++ b/Digitigrade/HttpResponseStatus/NoHandlerFound.php @@ -0,0 +1,18 @@ +message = "No handler found for path $path"; + } + + public function httpCode(): int { + return 404; + } + + public function httpReason(): string { + return "Not Found"; + } +} \ No newline at end of file diff --git a/Digitigrade/HttpResponseStatus/NotFound.php b/Digitigrade/HttpResponseStatus/NotFound.php new file mode 100644 index 0000000..643976c --- /dev/null +++ b/Digitigrade/HttpResponseStatus/NotFound.php @@ -0,0 +1,18 @@ +message = $reason ?? 'Request was handled but no appropriate resource found'; + } + + public function httpCode(): int { + return 404; + } + + public function httpReason(): string { + return "Not Found"; + } +} \ No newline at end of file -- cgit v1.3