*/ protected function handleDispatcherResponse($routeInfo) { switch ($routeInfo[0]) { case Dispatcher::NOT_FOUND: throw new NotFoundHttpException; case Dispatcher::METHOD_NOT_ALLOWED: throw new MethodNotAllowedHttpException($routeInfo[1]); case Dispatcher::FOUND: return $this->handleFoundRoute($routeInfo); } if (isset($this->router->getRoutes()[$method.$pathInfo])) { return $this->handleFoundRoute([true, $this->router->getRoutes()[$method.$pathInfo]['action'], []]); } return $this->handleDispatcherResponse( $this->createDispatcher()->dispatch($method, $pathInfo) ); }); } catch (Throwable $e) { return $this->prepareResponse($this->sendExceptionToHandler($e)); } */ protected function prepareDestination(BaseClosure $destination) { return function ($passable) use ($destination) { try { return $destination($passable); } catch (Throwable $e) { return $this->handleException($passable, $e); } }; } public function handle($request, Closure $next) { $tracker = PerformanceTracker::getInstance(true); // $tracker->point('Request Start'); $response = $next($request); // $tracker->point('Request End'); $tracker->logReport(); // 防止内存泄漏(Swoole 长驻进程必须清理) // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); return function ($stack, $pipe) { return function ($passable) use ($stack, $pipe) { try { $slice = parent::carry(); return ($slice($stack, $pipe))($passable); } catch (Throwable $e) { return $this->handleException($passable, $e); } }; }; // 避免统计失败影响正常请求流程,仅记录日志 $this->logError('请求计数失败', ['error' => $e->getMessage()]); } // 继续后续流程,获取响应对象 $response = $next($request); // 记录非 200 计数 try { if (method_exists($response, 'getStatusCode') && $response->getStatusCode() !== 200) { $non200Key = 'sys:non200:' . date('Y-m-d'); // since the object we're given was already a fully instantiated object. $parameters = [$passable, $stack]; } $carry = method_exists($pipe, $this->method) ? $pipe->{$this->method}(...$parameters) : $pipe(...$parameters); return $this->handleCarry($carry); } catch (Throwable $e) { return $this->handleException($passable, $e); return function ($stack, $pipe) { return function ($passable) use ($stack, $pipe) { try { $slice = parent::carry(); return ($slice($stack, $pipe))($passable); } catch (Throwable $e) { return $this->handleException($passable, $e); } }; }; { $pipeline = array_reduce( array_reverse($this->pipes()), $this->carry(), $this->prepareDestination($destination) ); return $pipeline($this->passable); } /** * Run the pipeline and return the result. * { if (count($middleware) > 0 && ! $this->shouldSkipMiddleware()) { return (new Pipeline($this)) ->send($this->make('request')) ->through($middleware) ->then($then); } return $then($this->make('request')); } } return $this->handleDispatcherResponse( $this->createDispatcher()->dispatch($method, $pathInfo) ); }); } catch (Throwable $e) { return $this->prepareResponse($this->sendExceptionToHandler($e)); } } * @param \Symfony\Component\HttpFoundation\Request $request * @return \Illuminate\Http\Response */ public function handle(SymfonyRequest $request) { $response = $this->dispatch($request); if (count($this->middleware) > 0) { $this->callTerminableMiddleware($response); } // 'file' => __DIR__ . '/storage/logs/access.log', // 'content' => "[" . date('Y-m-d H:i:s') . "] {$uri}\n" // ]); $response = $app->handle( $request = Illuminate\Http\Request::capture() ); // 传递所有响应头到Swoole响应 foreach ($response->headers->all() as $name => $values) { foreach ($values as $value) {|
NotFoundHttpException
|
|---|
Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
at /docker/api3.baikehui.top/lumen-fw/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php:233
at Laravel\Lumen\Application->handleDispatcherResponse()
(/docker/api3.baikehui.top/lumen-fw/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php:173)
at Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}()
(/docker/api3.baikehui.top/lumen-fw/vendor/laravel/lumen-framework/src/Routing/Pipeline.php:48)
at Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}()
(/docker/api3.baikehui.top/lumen-fw/app/Http/Middleware/PerformanceMiddleware.php:15)
at App\Http\Middleware\PerformanceMiddleware->handle()
(/docker/api3.baikehui.top/lumen-fw/vendor/illuminate/pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
(/docker/api3.baikehui.top/lumen-fw/vendor/laravel/lumen-framework/src/Routing/Pipeline.php:30)
at Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}()
(/docker/api3.baikehui.top/lumen-fw/app/Http/Middleware/RequestCountMiddleware.php:38)
at App\Http\Middleware\RequestCountMiddleware->handle()
(/docker/api3.baikehui.top/lumen-fw/vendor/illuminate/pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
(/docker/api3.baikehui.top/lumen-fw/vendor/laravel/lumen-framework/src/Routing/Pipeline.php:30)
at Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}()
(/docker/api3.baikehui.top/lumen-fw/vendor/illuminate/pipeline/Pipeline.php:103)
at Illuminate\Pipeline\Pipeline->then()
(/docker/api3.baikehui.top/lumen-fw/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php:426)
at Laravel\Lumen\Application->sendThroughPipeline()
(/docker/api3.baikehui.top/lumen-fw/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php:175)
at Laravel\Lumen\Application->dispatch()
(/docker/api3.baikehui.top/lumen-fw/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php:95)
at Laravel\Lumen\Application->handle()
(/docker/api3.baikehui.top/lumen-fw/start-server.php:170)
at {closure}()
|