aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/Router.php
diff options
context:
space:
mode:
authorThedro Neely <thedroneely@gmail.com>2018-08-30 04:30:53 -0400
committerThedro Neely <thedroneely@gmail.com>2018-08-30 04:30:53 -0400
commit2bdcd9d9283b44e7c35822aa1317013928006fd8 (patch)
treeca2bf097e4dfcfdabba36a5cb2643560ab03b926 /bootstrap/Router.php
downloadthedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.tar.gz
thedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.tar.bz2
thedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.zip
Initialize Repo: First Commit
Diffstat (limited to 'bootstrap/Router.php')
-rw-r--r--bootstrap/Router.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/bootstrap/Router.php b/bootstrap/Router.php
new file mode 100644
index 0000000..9673c36
--- /dev/null
+++ b/bootstrap/Router.php
@@ -0,0 +1,42 @@
+<?php
+
+class Router
+{
+ protected $routes = [
+ 'GET' => [],
+ 'POST' => [],
+ 'HEAD' => []
+ ];
+
+ public function get($uri, $controller)
+ {
+ $this->routes['GET'][$uri] = $controller;
+ }
+
+ public function post($uri, $controller)
+ {
+ $this->routes['POST'][$uri] = $controller;
+ }
+
+ public function head($uri, $controller)
+ {
+ $this->routes['HEAD'][$uri] = $controller;
+ }
+
+ public static function load($file)
+ {
+ $router = new static;
+ require $file;
+ return $router;
+ }
+
+ public function direct($uri, $requestType)
+ {
+ if (is_array($this->routes[$requestType]) && array_key_exists($uri, $this->routes[$requestType])) {
+ return $this->routes[$requestType][$uri];
+ }
+ // throw new Exception('No route defined for this URI: "'.$uri.'"');
+ http_response_code(404);
+ die(require '../app/views/404.view.php');
+ }
+}