Clean PHP code.

This commit is contained in:
Lars Jung 2015-05-12 03:26:44 +02:00
parent 9f53ddd3f3
commit 6258c40a24
2 changed files with 11 additions and 16 deletions

View file

@ -2,15 +2,13 @@
class Bootstrap { class Bootstrap {
private $basepath; public static function main() {
private $classpaths;
public function __construct($basepath) { (new Bootstrap())->run();
$this->basepath = $basepath;
$this->classpaths = ['/inc', '/inc/core', '/inc/ext'];
} }
private static $autopaths = ['core', 'ext'];
public function run() { public function run() {
spl_autoload_register([$this, 'autoload']); spl_autoload_register([$this, 'autoload']);
@ -19,7 +17,7 @@ class Bootstrap {
date_default_timezone_set(@date_default_timezone_get()); date_default_timezone_set(@date_default_timezone_get());
session_start(); session_start();
$this->once('config'); $this->once('../config');
$session = new Session($_SESSION); $session = new Session($_SESSION);
$request = new Request($_REQUEST); $request = new Request($_REQUEST);
@ -31,7 +29,7 @@ class Bootstrap {
} else { } else {
define('APP_HREF', $setup->get('APP_HREF')); define('APP_HREF', $setup->get('APP_HREF'));
define('FALLBACK', (new Fallback($app))->get_html()); define('FALLBACK', (new Fallback($app))->get_html());
$this->once('inc/page'); $this->once('page');
} }
} }
@ -39,8 +37,8 @@ class Bootstrap {
$filename = 'class-' . strtolower($class_name) . '.php'; $filename = 'class-' . strtolower($class_name) . '.php';
foreach ($this->classpaths as $classpath) { foreach (Bootstrap::$autopaths as $path) {
$file = $this->basepath . $classpath . '/' . $filename; $file = __DIR__ . '/' . $path . '/' . $filename;
if (file_exists($file)) { if (file_exists($file)) {
require_once $file; require_once $file;
return true; return true;
@ -50,6 +48,6 @@ class Bootstrap {
private function once($lib) { private function once($lib) {
require_once $this->basepath . '/' . $lib . '.php'; require_once __DIR__ . '/' . $lib . '.php';
} }
} }

View file

@ -8,8 +8,5 @@ if (version_compare(PHP_VERSION, MIN_PHP_VERSION, '<')) {
exit; exit;
} }
$basepath = preg_replace('#[\\\\/]+#', '/', dirname(__FILE__)); require_once __DIR__ . '/inc/class-bootstrap.php';
require_once $basepath . '/inc/class-bootstrap.php'; Bootstrap::main();
$bootstrap = new Bootstrap($basepath);
$bootstrap->run();