diff options
Diffstat (limited to 'WpfTest/HttpResponseStatus')
| -rw-r--r-- | WpfTest/HttpResponseStatus/BadRequest.php | 18 | ||||
| -rw-r--r-- | WpfTest/HttpResponseStatus/InternalServerError.php | 23 | ||||
| -rw-r--r-- | WpfTest/HttpResponseStatus/NoHandlerFound.php | 18 | ||||
| -rw-r--r-- | WpfTest/HttpResponseStatus/NotFound.php | 18 |
4 files changed, 77 insertions, 0 deletions
diff --git a/WpfTest/HttpResponseStatus/BadRequest.php b/WpfTest/HttpResponseStatus/BadRequest.php new file mode 100644 index 0000000..74fab3c --- /dev/null +++ b/WpfTest/HttpResponseStatus/BadRequest.php @@ -0,0 +1,18 @@ +<?php +namespace WpfTest\HttpResponseStatus; + +use WpfTest\HttpResponseStatus; + +class BadRequest extends \Exception implements HttpResponseStatus { + public function __construct(?string $reason) { + $this->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/WpfTest/HttpResponseStatus/InternalServerError.php b/WpfTest/HttpResponseStatus/InternalServerError.php new file mode 100644 index 0000000..11b67f3 --- /dev/null +++ b/WpfTest/HttpResponseStatus/InternalServerError.php @@ -0,0 +1,23 @@ +<?php +namespace WpfTest\HttpResponseStatus; + +use WpfTest\GlobalConfig; +use WpfTest\HttpResponseStatus; + +class InternalServerError extends \Exception implements HttpResponseStatus { + public function __construct(\Throwable $reason, ?string $context = null) { + $this->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/WpfTest/HttpResponseStatus/NoHandlerFound.php b/WpfTest/HttpResponseStatus/NoHandlerFound.php new file mode 100644 index 0000000..9ceeb0b --- /dev/null +++ b/WpfTest/HttpResponseStatus/NoHandlerFound.php @@ -0,0 +1,18 @@ +<?php +namespace WpfTest\HttpResponseStatus; + +use WpfTest\HttpResponseStatus; + +class NoHandlerFound extends \Exception implements HttpResponseStatus { + public function __construct(string $path) { + $this->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/WpfTest/HttpResponseStatus/NotFound.php b/WpfTest/HttpResponseStatus/NotFound.php new file mode 100644 index 0000000..b36d0a3 --- /dev/null +++ b/WpfTest/HttpResponseStatus/NotFound.php @@ -0,0 +1,18 @@ +<?php +namespace WpfTest\HttpResponseStatus; + +use WpfTest\HttpResponseStatus; + +class NotFound extends \Exception implements HttpResponseStatus { + public function __construct(?string $reason) { + $this->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 |
