From a84232811dadccf7047424f27340a7f9847bedff Mon Sep 17 00:00:00 2001 From: winter Date: Sat, 7 Dec 2024 21:44:42 +0000 Subject: many many changes but actors are loaded from db now --- WpfTest/Router.php | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'WpfTest/Router.php') diff --git a/WpfTest/Router.php b/WpfTest/Router.php index ea71657..c975723 100644 --- a/WpfTest/Router.php +++ b/WpfTest/Router.php @@ -1,51 +1,48 @@ requestPath = $_GET['requestPath'] ?? $_SERVER['PATH_INFO'] ?? explode('?', $_SERVER['REQUEST_URI'], 2)[0] ?? '/'; $this->routes = []; } /** - * @return Router the singleton instance + * Processes and sends a response to the current request + * @return void */ - public static function getInstance() { - if (!isset(self::$instance)) { - self::$instance = new self(); - } - return self::$instance; - } - public function processRequest() { try { $this->processRequestInner(); - } catch (HttpReturnStatus $e) { + } catch (HttpResponseStatus $e) { http_response_code($e->httpCode()); echo '

' . $e->httpReason() . '

' . $e->getMessage() . '
'; } } private function processRequestInner() { + $context = null; try { $route = $this->matchPath($this->requestPath); if ($route == null) { throw new NoHandlerFound($this->requestPath); } + $context = 'handler for /' . implode('/', $route[0]); $route[1]($route[2]); // call handler with args } catch (\Exception $e) { - if (is_a($e, HttpReturnStatus::class)) { + if (is_a($e, HttpResponseStatus::class)) { throw $e; } - throw new InternalServerError($e); + throw new InternalServerError($e, $context); + } catch (\Error $e) { + throw new InternalServerError($e, $context); } } -- cgit v1.3