This commit is contained in:
Gregory Letellier
2023-11-14 11:18:23 +01:00
commit 13c80f5642
15 changed files with 509 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<?php
namespace Kletellier\MiniWeb\Core\Routing;
use Bramus\Router\Router as RouterRouter;
use Kletellier\MiniWeb\Core\Kernel\Container;
class Router
{
private $_router;
private $_root;
public function __construct()
{
$this->_root = Container::get("ROOT");
$this->init();
}
public function run()
{
$this->_router->run();
}
private function init()
{
$this->_router = new RouterRouter();
$this->loadFromFile($this->_root . DIRECTORY_SEPARATOR . "routes");
$this->_router->set404("404 - Not found");
}
private function loadFromFile($path)
{
if (is_dir($path)) {
$router = $this->_router;
require $path . DIRECTORY_SEPARATOR . "routes.php";
}
}
}