getResponseFactory()); } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $current_user = $request->getAttribute('current_user'); if (!$current_user instanceof User) { throw new LogicException('The route that has this middleware must have the CurrentUserMiddleware before this one'); } if (!$current_user->is_admin) { $response = $this->responseFactory->createResponse(403); $response->getBody()->write('Forbidden'); return $response->withHeader('Content-Type', 'text/plain'); } return $handler->handle($request); } }