From 6258c40a24dd36ebb98ecfe0f8e60898345fcc70 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Tue, 12 May 2015 03:26:44 +0200 Subject: [PATCH] Clean PHP code. --- src/_h5ai/server/php/inc/class-bootstrap.php | 20 +++++++++----------- src/_h5ai/server/php/index.php | 7 ++----- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/_h5ai/server/php/inc/class-bootstrap.php b/src/_h5ai/server/php/inc/class-bootstrap.php index cbd53219..2f0fe56f 100644 --- a/src/_h5ai/server/php/inc/class-bootstrap.php +++ b/src/_h5ai/server/php/inc/class-bootstrap.php @@ -2,15 +2,13 @@ class Bootstrap { - private $basepath; - private $classpaths; + public static function main() { - public function __construct($basepath) { - - $this->basepath = $basepath; - $this->classpaths = ['/inc', '/inc/core', '/inc/ext']; + (new Bootstrap())->run(); } + private static $autopaths = ['core', 'ext']; + public function run() { spl_autoload_register([$this, 'autoload']); @@ -19,7 +17,7 @@ class Bootstrap { date_default_timezone_set(@date_default_timezone_get()); session_start(); - $this->once('config'); + $this->once('../config'); $session = new Session($_SESSION); $request = new Request($_REQUEST); @@ -31,7 +29,7 @@ class Bootstrap { } else { define('APP_HREF', $setup->get('APP_HREF')); 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'; - foreach ($this->classpaths as $classpath) { - $file = $this->basepath . $classpath . '/' . $filename; + foreach (Bootstrap::$autopaths as $path) { + $file = __DIR__ . '/' . $path . '/' . $filename; if (file_exists($file)) { require_once $file; return true; @@ -50,6 +48,6 @@ class Bootstrap { private function once($lib) { - require_once $this->basepath . '/' . $lib . '.php'; + require_once __DIR__ . '/' . $lib . '.php'; } } diff --git a/src/_h5ai/server/php/index.php b/src/_h5ai/server/php/index.php index 5cdb9013..31c2257f 100644 --- a/src/_h5ai/server/php/index.php +++ b/src/_h5ai/server/php/index.php @@ -8,8 +8,5 @@ if (version_compare(PHP_VERSION, MIN_PHP_VERSION, '<')) { exit; } -$basepath = preg_replace('#[\\\\/]+#', '/', dirname(__FILE__)); -require_once $basepath . '/inc/class-bootstrap.php'; - -$bootstrap = new Bootstrap($basepath); -$bootstrap->run(); +require_once __DIR__ . '/inc/class-bootstrap.php'; +Bootstrap::main();