From 2683a5b4bb20f0cb4fe7fa4fb1e70a91c1e3933c Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Thu, 11 Jul 2024 18:17:51 -0500 Subject: [PATCH] Begin rework on app structure --- public/index.php | 15 ++++++++++++++- server/app/app.php | 14 ++++++++++++++ server/bootstrap.php | 29 ++++++++++++++++++++++++----- server/modules/HomeModule.php | 9 +++++++++ 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 server/modules/HomeModule.php diff --git a/public/index.php b/public/index.php index 20b9beb..fb34207 100644 --- a/public/index.php +++ b/public/index.php @@ -1,6 +1,19 @@ uri(0); +$routes = [ + 'home' => 'HomeModule::home', +]; diff --git a/server/app/app.php b/server/app/app.php index 74f73eb..77e986e 100644 --- a/server/app/app.php +++ b/server/app/app.php @@ -14,4 +14,18 @@ class App self::$req = new Request(); // the current request self::$db = new Database($dbPath); // the database } + + public function route(string $uri, array $routes) + { + // check if the module exists + if (isset($routes[$module])) { + // if the module exists, call the module's handle method + $routes[$module]($this); + } else { + // if the module does not exist, render a 404 page + $this->render('404', [ + 'title' => '404', + ]); + } + } } diff --git a/server/bootstrap.php b/server/bootstrap.php index 4a94dcc..79c3823 100644 --- a/server/bootstrap.php +++ b/server/bootstrap.php @@ -1,15 +1,34 @@ - 'path/to/class.php', + + // server-level classes + 'App' => SERVER.'/app/app.php', + 'Database' => SERVER.'/app/database.php', + 'Request' => SERVER.'/app/request.php', + + // modules + 'HomeModule' => SERVER.'/modules/HomeModule.php', +]; + +// autoloader +spl_autoload_register(function($class) { + if (isset(MAP[$class])) require_once MAP[$class]; +}); diff --git a/server/modules/HomeModule.php b/server/modules/HomeModule.php new file mode 100644 index 0000000..58de3fb --- /dev/null +++ b/server/modules/HomeModule.php @@ -0,0 +1,9 @@ +