container = $container; } /** * 登录状态校验 * @param ServerRequestInterface $request * @param RequestHandlerInterface $handler * @return ResponseInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { // 登录权限校验 $request = $request->withAttribute("isLogin", false); try { $token = $request->getHeaderLine("Authorization",""); $result = Account::checkToken(str_replace("Bearer ","", $token)); if ($result) { // 是否登录 $request = $request->withAttribute("isLogin",true); // 账号信息 $request = $request->withAttribute("account", $result); } }catch (\Exception $exception){ var_dump($exception->getMessage()); } // 上下文中记录账号信息 Context::set(ServerRequestInterface::class, $request); return $handler->handle($request); } }