diff options
author | Thedro Neely <thedroneely@gmail.com> | 2018-08-30 04:40:53 -0400 |
---|---|---|
committer | Thedro Neely <thedroneely@gmail.com> | 2018-08-30 04:40:53 -0400 |
commit | 2659205908bd5cab508f4ff817123673e078ab74 (patch) | |
tree | e455f36b124e9b98f7005e6d4310b71881734623 /bootstrap/Router.php | |
download | edwinmattiacci.com-2659205908bd5cab508f4ff817123673e078ab74.tar.gz edwinmattiacci.com-2659205908bd5cab508f4ff817123673e078ab74.tar.bz2 edwinmattiacci.com-2659205908bd5cab508f4ff817123673e078ab74.zip |
Initialize Repo: First Commit
Diffstat (limited to 'bootstrap/Router.php')
-rw-r--r-- | bootstrap/Router.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/bootstrap/Router.php b/bootstrap/Router.php new file mode 100644 index 0000000..a098c30 --- /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 '../views/404.view.php'); + } +} |