Begin rework on app structure
This commit is contained in:
parent
13c2f7fb4b
commit
2683a5b4bb
|
@ -1,6 +1,19 @@
|
||||||
<?php // index.php :: Primary program script, evil alien overlord, you decide.
|
<?php // index.php :: Primary program script, evil alien overlord, you decide.
|
||||||
|
|
||||||
|
// define our server path and bootstrap the request
|
||||||
const SERVER = '../server';
|
const SERVER = '../server';
|
||||||
require_once SERVER.'/bootstrap.php';
|
require_once SERVER.'/bootstrap.php';
|
||||||
|
|
||||||
if (!installed()) redirect('/install');
|
// check if the server has been installed
|
||||||
|
if (!installed()) redirect('/install');
|
||||||
|
|
||||||
|
// spin up our app container
|
||||||
|
$app = new App(DB);
|
||||||
|
|
||||||
|
// route the request
|
||||||
|
// routing follows a simple rule; the first segment of the URI is the
|
||||||
|
// module, and the module handles the rest
|
||||||
|
$route = App::$req->uri(0);
|
||||||
|
$routes = [
|
||||||
|
'home' => 'HomeModule::home',
|
||||||
|
];
|
||||||
|
|
|
@ -14,4 +14,18 @@ class App
|
||||||
self::$req = new Request(); // the current request
|
self::$req = new Request(); // the current request
|
||||||
self::$db = new Database($dbPath); // the database
|
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',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,34 @@
|
||||||
<?php // bootstrap.php :: Initialize all our boring stuff
|
<?php
|
||||||
|
|
||||||
|
// @todo use a flag for this
|
||||||
ini_set('display_errors', 'on');
|
ini_set('display_errors', 'on');
|
||||||
error_reporting(E_ALL | E_STRICT);
|
error_reporting(E_ALL | E_STRICT);
|
||||||
|
|
||||||
$start = microtime(true);
|
define('START', microtime(true)); // start the timer for this execution
|
||||||
|
|
||||||
session_start();
|
session_start(); // initialize the session engine
|
||||||
|
|
||||||
|
// @todo move these to a settings config somewhere
|
||||||
const VERSION = '1.1.11';
|
const VERSION = '1.1.11';
|
||||||
const BUILD = '';
|
const BUILD = '';
|
||||||
const DB = SERVER.'/database/dragon.db';
|
const DB = SERVER.'/database/dragon.db';
|
||||||
|
|
||||||
require_once SERVER.'/library.php';
|
require_once SERVER.'/library.php'; // include our miscellaneous functions
|
||||||
require_once SERVER.'/database.php';
|
|
||||||
|
// autoloader map
|
||||||
|
const MAP = [
|
||||||
|
// 'Class' => '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];
|
||||||
|
});
|
||||||
|
|
9
server/modules/HomeModule.php
Normal file
9
server/modules/HomeModule.php
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class HomeModule
|
||||||
|
{
|
||||||
|
public static function home(App $app)
|
||||||
|
{
|
||||||
|
echo 'Welcome to the home module!';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user