Skip to content

Commit 7d5f9d8

Browse files
Some documentation improvements. (#315)
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
1 parent 9f562d8 commit 7d5f9d8

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎src/guide/structure/middleware.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ return [
111111
To 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

117117
There 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
153153
handling 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

159162
In 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

166169
To get it in the next middleware:
@@ -174,7 +177,7 @@ $answer = $request->getAttribute('answer');
174177
You 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
179182
return $response;
180183
```

0 commit comments

Comments
 (0)