@@ -111,7 +111,7 @@ return [
111111To create middleware, you need to implement a single ` process ` method of ` Psr\Http\Server\MiddlewareInterface ` :
112112
113113``` php
114- public function process(ServerRequestInterface $request, RequestHandlerInterface $next ): ResponseInterface;
114+ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface;
115115```
116116
117117There are multiple ways to handle a request, and choosing one depends on what the middleware should achieve.
@@ -138,7 +138,7 @@ final readonly class RespondingMiddleware implements MiddlewareInterface
138138 {
139139 }
140140
141- public function process(ServerRequestInterface $request, RequestHandlerInterface $next ): ResponseInterface
141+ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface
142142 {
143143 $response = $this->responseFactory->createResponse();
144144 $response->getBody()->write('Hello!');
@@ -153,14 +153,17 @@ If middleware either isn't intended to form a response or change the request or
153153handling could be left to the next middleware in the stack:
154154
155155``` php
156- return $next->handle($request);
156+ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
157+ {
158+ return $handler->handle($request);
159+ }
157160```
158161
159162In case you need to pass data to the next middleware, you can use request attributes:
160163
161164``` php
162165$request = $request->withAttribute('answer', 42);
163- return $next ->handle();
166+ return $handler ->handle($request );
164167```
165168
166169To get it in the next middleware:
@@ -174,7 +177,7 @@ $answer = $request->getAttribute('answer');
174177You may want to capture the response to manipulate it. It could be useful for adding CORS headers, gzipping content, etc.
175178
176179``` php
177- $response = $next ->handle($request);
180+ $response = $handler ->handle($request);
178181// extra handing
179182return $response;
180183```
0 commit comments