设置中间件
Router::group(['middle' => [\App\Test\MixPro\TestMiddle::class . '@checkSession']], function () {
Router::get('/mix/ws', HttpController::class . '@ws');
Router::get('/mix/http', HttpController::class . '@http');
Router::post('/mix/http/loop', HttpController::class . '@httpLoop');
Router::post('/mix/http/send', HttpController::class . '@httpSend');
});
// 中间件代码
class TestMiddle
{
public function checkSession($next, Response $response)
{
$name = $response->session()->get('name');
if (!$name) {
return '<a href="/login">请登录</a>';
}
return $next();
}
}
设置命名空间前缀
Router::group(['namespace'=>'App\\Test\\WebSocket'],function (){
Router::set('ws','/a','TestController@abc');
Router::set('ws','/b','TestController@bbb');
});