- app
- Exception
- Http
- Controllers
- Middleware
- Libs
- Models
- Services
- bootstrap
- app.php
- config
- app.php
- database.php
- logging.php
- public
- index.php
- routes
web.php
- storage
主目录结构
入口文件为 public下的index.php
,该文件为系统的统一入口,代码极为简单,载入启动程序bootstrap.php后run()
。
<?php
$app = require_once __DIR__.'/../bootstrap/app.php';
$app->run();
系统的启动程序为bootstrap.php
, 该程序主要加载配置项,实例化APP类,加载中间件、路由等功能,返回最终的APP对象。
<?php
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR . '..');
define('APP_PATH', ROOT_PATH . DIRECTORY_SEPARATOR . 'app');
//require __DIR__.'/../vendor/autoload.php';
require __DIR__ . '/../system/autoload.php';
require_once __DIR__ . '/../system/helpers.php';
$app = new System\Application(dirname(__DIR__), ['web']);
$file = '.env';
if (isset($_SERVER["env"])) {
if ($_SERVER["env"] == 'test') {
$file = '.env_test';
} else if ($_SERVER["env"] == 'production') {
$file = '.env_production';
}
}
$app->loadEnv($file);
$app->beforeMiddleware([
App\Http\Middleware\BeforeMiddleware::class,
]);
$app->afterMiddleware([
App\Http\Middleware\AfterMiddleware::class
]);
$app->routeMiddleware([
'auth' => App\Http\Middleware\AuthMiddleware::class,
'auth2' => App\Http\Middleware\Auth2Middleware::class
]);
return $app;