From 15de85bf59fbf8f3fa9b94bddba91ccc68b701b8 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 15 May 2015 15:25:33 +0200 Subject: [PATCH] implement simple maintenance switch --- app/Web.php | 46 ++++++++++++++++++++++++--------------------- app/views/503.phtml | 12 ++++++++++++ 2 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 app/views/503.phtml diff --git a/app/Web.php b/app/Web.php index 0353a99..b7bc23c 100644 --- a/app/Web.php +++ b/app/Web.php @@ -24,27 +24,31 @@ class Web } function __invoke(Dispatcher $dispatcher) { - $route = $dispatcher->dispatch($this->request->getRequestMethod(), - $this->baseUrl->pathinfo($this->request->getRequestUrl())); - - switch ($route[0]) { - case Dispatcher::NOT_FOUND: - $this->display(404, null, 404); - break; - - case Dispatcher::METHOD_NOT_ALLOWED: - $this->display(405, null, 405, ["Allowed" => $route[1]]); - break; - - case Dispatcher::FOUND: - list(, $handler, $args) = $route; - try { - $handler(array_map("urldecode", $args)); - } catch (\Exception $exception) { - self::cleanBuffers(); - $this->display(500, compact("exception"), 500, ["X-Exception", get_class($exception)]); - } - break; + if (!file_exists("../config/maintenance")) { + $route = $dispatcher->dispatch($this->request->getRequestMethod(), + $this->baseUrl->pathinfo($this->request->getRequestUrl())); + + switch ($route[0]) { + case Dispatcher::NOT_FOUND: + $this->display(404, null, 404); + break; + + case Dispatcher::METHOD_NOT_ALLOWED: + $this->display(405, null, 405, ["Allowed" => $route[1]]); + break; + + case Dispatcher::FOUND: + list(, $handler, $args) = $route; + try { + $handler(array_map("urldecode", $args)); + } catch (\Exception $exception) { + self::cleanBuffers(); + $this->display(500, compact("exception"), 500, ["X-Exception", get_class($exception)]); + } + break; + } + } else { + $this->display(503, null, 503); } $this->response->send(); diff --git a/app/views/503.phtml b/app/views/503.phtml new file mode 100644 index 0000000..a22bc2b --- /dev/null +++ b/app/views/503.phtml @@ -0,0 +1,12 @@ +layout("layout") ?> + + + + + -- 2.30.2