Explorar el Código

Added comments to the bootstrap process

Lukas Angerer hace 4 años
padre
commit
d8935cf25a
Se han modificado 2 ficheros con 11 adiciones y 2 borrados
  1. 10 1
      src/bootstrap.php
  2. 1 1
      src/routes/api-get-data.php

+ 10 - 1
src/bootstrap.php

@@ -6,13 +6,22 @@
 require_once __DIR__ . "/autoloader.php";
 AutoLoader::registerLoader();
 
+// Build a registry of routes by scanning the "routes" directory and loading all the files in there.
 Router::scan("routes/*.php");
+
+// Now, we try to find the route that matches the given request URI (actually _path_) and HTTP method.
 $route = Router::findRoute($_SERVER["REQUEST_URI"], $_SERVER["REQUEST_METHOD"]);
 
+// We do some more output buffering in order to avoid problems with setting
+// the HTTP status code or headers too late
 ob_start();
+
+// This down here can be useful for debugging ;)
 //var_dump($route);
 
+// Just execute the route ...
 $route->execute();
-$output = ob_get_clean();
 
+// ... and print the result
+$output = ob_get_clean();
 print($output);

+ 1 - 1
src/routes/api-get-data.php

@@ -45,6 +45,6 @@ Router::register(new LogicAction("/api/getdata", "GET", function () {
         ));
     }
 
-    header('Content-type: application/json');
+    header('Content-Type: application/json');
     print(json_encode($data, JSON_PRETTY_PRINT));
 }));