first commit

This commit is contained in:
2024-08-29 21:50:55 -07:00
parent c112a89d85
commit 65c2bb289b
5 changed files with 143 additions and 2 deletions

43
src/Router.php Normal file
View File

@@ -0,0 +1,43 @@
<?php
class Router {
public $routes = [];
public $query = [];
public $path;
public $controllerPath = BASEPATH . '/App/controllers/404.php';
public function __construct() {
$this->loadRoutes();
$this->preparePath();
$this->prepareQuery();
$this->setRouteFile();
}
private function loadRoutes() {
require_once( BASEPATH . '/App/routes.php');
$this->routes = $routes;
}
private function preparePath() {
$this->path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
}
private function prepareQuery() {
$parsedUri = parse_url($_SERVER['REQUEST_URI']);
$queryArray = [];
if (isset($parsedUri['query'])) {
parse_str($parsedUri['query'], $queryArray);
}
$this->query = $queryArray;
}
private function setRouteFile() {
foreach ($this->routes as $key => $value) {
if ( $this->path == $key) {
$this->controllerPath = BASEPATH . '/App/controllers/' . $value['file'] . '.php';
break;
}
}
}
}