Skip to content

Commit

Permalink
perf: ⚡️ 插件系统路由提升
Browse files Browse the repository at this point in the history
  • Loading branch information
aoaostar committed Sep 19, 2022
1 parent 618c483 commit eb5d2d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/middleware/PluginCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class PluginCheck
public function handle($request, \Closure $next)
{
$plugin = plugin_info_get(plugin_alias_get());
if (!$plugin->isExists()) {
abort(400, '该插件不存在');
}
if ($plugin->enable !== 1) {
abort(400, '该插件已禁用');
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function plugin_template_path_get($pluginClass = ""): string
}


function plugin_info_get($alias = '')
function plugin_info_get($alias = ''): \app\model\Plugin
{
return \app\model\Plugin::getByAlias($alias);
}
Expand Down
10 changes: 5 additions & 5 deletions route/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Route::rule('api/:alias/[:method]', "Plugin/api")
->pattern([
'alias' => '[\w|\-/]+',
'alias' => '[\w|\-]+',
])
->middleware(\app\middleware\PluginCheck::class);

Expand All @@ -13,13 +13,13 @@

Route::group(':alias', function () {

Route::get('/static/:path', 'static');
Route::get('/', 'index');
Route::get('/static/*', 'static');
Route::get('/[:path]', 'index');

})->prefix('Plugin/')
->pattern([
'alias' => '[\w|\-/]+',
'path' => '[\w|\-/]+',
'alias' => '[\w|\-]+',
'path' => '[\w\W]+',
])
->middleware(\app\middleware\PluginCheck::class)
->middleware(\app\middleware\View::class);

0 comments on commit eb5d2d9

Please sign in to comment.