mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-30 15:05:15 -04:00
Clean PHP code.
This commit is contained in:
parent
9f53ddd3f3
commit
6258c40a24
2 changed files with 11 additions and 16 deletions
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue