@NauxLiu thx, 我没留意5.1的情况. 5.3中 lumen和laravel都已经改掉了.
Lumen5.3:
protected function callTerminableMiddleware($response)
{
if ($this->shouldSkipMiddleware()) {
return;
}
$response = $this->prepareResponse($response);
foreach ($this->middleware as $middleware) {
if (! is_string($middleware)) {
continue;
}
$instance = $this->make(explode(':', $middleware)[0]);
if (method_exists($instance, 'terminate')) {
$instance->terminate($this->make('request'), $response);
}
}
}
目前如果需要在路由中间件中使用terminate 要么用后置中间件替代. 不然就得建立两个中间件. 一个全局单独处理terminate, 一个路由中间件处理主要逻辑比方说 session start. 只想到这两种方案了.