/**
* 中间件调度
* @access public
* @param Request $request
* @param string $type 中间件类型
*/
public function dispatch(Request $request, $type = 'route')
{
return call_user_func($this->resolve($type), $request);
}
protected function resolve($type = 'route')
{
return function (Request $request) use ($type) {
$middleware = array_shift($this->queue[$type]);
if (null === $middleware) {
throw new InvalidArgumentException('The queue was exhausted, with no response returned');
}
list($call, $param) = $middleware;
try {
$response = call_user_func_array($call, [$request, $this->resolve($type), $param]);
} catch (HttpResponseException $exception) {
$response = $exception->getResponse();
}
if (!$response instanceof Response) {
throw new LogicException('The middleware must return Response instance');
}
return $response;
};
}
重点讲解一下resolve方法,有个递归好想,没看懂