File tree Expand file tree Collapse file tree 3 files changed +17
-25
lines changed
Expand file tree Collapse file tree 3 files changed +17
-25
lines changed Original file line number Diff line number Diff line change 33define ('APP_ROOT ' , strtr (__DIR__ , '\\' , '/ ' ) . '/ ' );
44
55require APP_ROOT . 'library/autoload.php ' ;
6-
7- App::boot (
8- $ argv [1 ] ?? array_shift ($ _GET )
9- );
6+ App::boot ($ argv [1 ] ?? reset ($ _GET ));
Original file line number Diff line number Diff line change 22
33class App
44{
5- /**
6- * @var AppRouter $router
7- */
8- public static $ router ;
9-
105 /**
116 * 启动指定模块
127 * @param string $url
138 * @return void
149 */
1510 public static function boot ($ url )
1611 {
17- // 注册页面路由器
18- self ::$ router = new AppRouter ();
19- require APP_MODULES . 'route.php ' ;
20- $ match = self ::$ router ->match ($ url ?: '/ ' );
21- call_user_func ($ match ['target ' ], $ match ['params ' ])->output ();
12+ $ router = new AppRouter ();
13+ if (is_file (APP_MODULES . 'route.php ' )) {
14+ require APP_MODULES . 'route.php ' ;
15+ }
16+ // 回退路由
17+ $ router ->map ('GET ' , '* ' , function ($ args ) {
18+ $ model = new ErrorModel ($ args );
19+ $ model ->warning ('not found ' , $ args );
20+ return $ model ;
21+ });
22+ // 匹配路由
23+ $ request = $ router ->match ($ url ?: '/ ' );
24+ $ request ['target ' ]($ request ['params ' ])->output ();
2225 }
2326
2427 /**
Original file line number Diff line number Diff line change 22
33// 默认首页
44
5- self :: $ router ->map ('GET ' , '/ ' , function ($ args ) {
5+ $ router ->map ('GET ' , '/ ' , function ($ args ) {
66 $ model = new HomeModel ();
77 $ model ->view ($ args );
88 return $ model ;
99});
1010
1111// 重建缓存
1212
13- self :: $ router ->map ('GET ' , '/admin/build ' , function ($ args ) {
13+ $ router ->map ('GET ' , '/admin/build ' , function ($ args ) {
1414 $ model = new AdminModel ();
1515 $ model ->build ($ args );
1616 return $ model ;
2121foreach (App::cache ('index ' ) as $ category ) {
2222 foreach ($ category ['routes ' ] as $ route ) {
2323 $ rt = $ route + ['cid ' => $ category ['id ' ]];
24- self :: $ router ->map ($ rt ['method ' ], $ rt ['route ' ], function ($ args ) use ($ rt ) {
24+ $ router ->map ($ rt ['method ' ], $ rt ['route ' ], function ($ args ) use ($ rt ) {
2525 $ model = new $ rt ['model ' ](); // 初始化模型
2626 $ model ->{$ rt ['action ' ]}($ rt + $ args );
2727 return $ model ;
2828 });
2929 }
3030}
31-
32- // 回退路由
33-
34- self ::$ router ->map ('GET ' , '* ' , function ($ args ) {
35- $ model = new ErrorModel ($ args );
36- $ model ->warning ('not found ' , $ args );
37- return $ model ;
38- });
You can’t perform that action at this time.
0 commit comments