implement simple maintenance switch
authorMichael Wallner <mike@php.net>
Fri, 15 May 2015 13:25:33 +0000 (15:25 +0200)
committerMichael Wallner <mike@php.net>
Fri, 15 May 2015 17:47:17 +0000 (19:47 +0200)
app/Web.php
app/views/503.phtml [new file with mode: 0644]

index 0353a996c2b75e97a9a653c9495395a1684ce458..b7bc23ceea1456fed244bb786a02e5a142081a62 100644 (file)
@@ -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 (file)
index 0000000..a22bc2b
--- /dev/null
@@ -0,0 +1,12 @@
+<?php $this->layout("layout") ?>
+
+<div class="page-header">
+       <h1>Service unavailable <small>503</small></h1>
+</div>
+
+
+<div class="alert alert-warning" role="alert">
+       <strong>We're down for maintenance!</strong>
+       <br>
+       Sorry &amp; keep tuned!
+</div>