use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ResponseInterface; class MyMiddleware { public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $responseMethod = $request->getAttribute(\Bref\Context\Context::RESPONSE_METHOD); // Do something based on the response method (e.g. GET or POST) return $handler->handle($request); } }
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $request = Request::createFromGlobals(); if ($request->getMethod() === 'POST') { $responseMethod = $request->attributes->get('response_method'); // Do something based on the response method (e.g. GET or POST) $response = new Response('Hello world!', 200); } else { $response = new Response('Invalid request method', 405); } $response->send();In this example, we create a Symfony HTTP Foundation request object from the global $_SERVER and $_POST variables. We then check if the request method is POST and retrieve the response method from the request attributes. Depending on the response method, we return a "Hello world!" response or an error message. Package/Library: Symfony HttpFoundation.