设置中间件

  1. Router::group(['middle' => [\App\Test\MixPro\TestMiddle::class . '@checkSession']], function () {
  2. Router::get('/mix/ws', HttpController::class . '@ws');
  3. Router::get('/mix/http', HttpController::class . '@http');
  4. Router::post('/mix/http/loop', HttpController::class . '@httpLoop');
  5. Router::post('/mix/http/send', HttpController::class . '@httpSend');
  6. });
  7. // 中间件代码
  8. class TestMiddle
  9. {
  10. public function checkSession($next, Response $response)
  11. {
  12. $name = $response->session()->get('name');
  13. if (!$name) {
  14. return '<a href="/login">请登录</a>';
  15. }
  16. return $next();
  17. }
  18. }

设置命名空间前缀

  1. Router::group(['namespace'=>'App\\Test\\WebSocket'],function (){
  2. Router::set('ws','/a','TestController@abc');
  3. Router::set('ws','/b','TestController@bbb');
  4. });