diff --git a/controller/Controller.class.php b/controller/Controller.class.php index 2708f7a6..ca23e6a0 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -60,6 +60,12 @@ class Controller { return NavActions::execute404(); } + catch (\Routing\HttpMethodNotAllowedException $e) + { + Response::setStatus(405); + Response::setHeader('Allow', implode(', ', $e->getAllowedMethods())); + return ['page/404']; + } } protected static function getRouterWithRoutes(): \Routing\RouteCollector diff --git a/data/i18n/en.yaml b/data/i18n/en.yaml index 84feb73a..ee88d4bd 100644 --- a/data/i18n/en.yaml +++ b/data/i18n/en.yaml @@ -93,6 +93,7 @@ news: next: Next prev: Previous page: + badmethod: HTTP method not allowed faq: back: Back to FAQ header: Frequently Asked Questions diff --git a/lib/routing/Dispatcher.class.php b/lib/routing/Dispatcher.class.php index c45c8569..44574109 100644 --- a/lib/routing/Dispatcher.class.php +++ b/lib/routing/Dispatcher.class.php @@ -175,7 +175,7 @@ class Dispatcher $this->matchedRoute = $routes; - throw new HttpMethodNotAllowedException('Allow: ' . implode(', ', array_keys($routes))); + throw new HttpMethodNotAllowedException(array_keys($routes), 'Method not allowed'); } /** diff --git a/lib/routing/HttpMethodNotAllowedException.class.php b/lib/routing/HttpMethodNotAllowedException.class.php index 79827882..00a09e14 100644 --- a/lib/routing/HttpMethodNotAllowedException.class.php +++ b/lib/routing/HttpMethodNotAllowedException.class.php @@ -1,5 +1,19 @@ -allowedMethods = $allowedMethods; + parent::__construct($message, $code, $previous); + } + + public function getAllowedMethods() + { + return $this->allowedMethods; + } +} diff --git a/view/template/page/405.php b/view/template/page/405.php new file mode 100644 index 00000000..bdb5c62e --- /dev/null +++ b/view/template/page/405.php @@ -0,0 +1,7 @@ + false]) ?> +
+
+

{{page.badmethod}}

+

{{page.funnier}}

+
+
\ No newline at end of file