1 | <?php |
||
2 | namespace Yiisoft\Yii\Web\Middleware; |
||
3 | |||
4 | use Psr\Http\Message\ResponseInterface; |
||
5 | use Psr\Http\Message\ServerRequestInterface; |
||
6 | use Psr\Http\Server\MiddlewareInterface; |
||
7 | use Psr\Http\Server\RequestHandlerInterface; |
||
8 | |||
9 | /** |
||
10 | * Tags request with a random value that could be later used for identifying it. |
||
11 | */ |
||
12 | class TagRequest implements MiddlewareInterface |
||
13 | { |
||
14 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
15 | { |
||
16 | $handler->handle($request->withAttribute('requestTag', $this->getRequestTag())); |
||
0 ignored issues
–
show
|
|||
17 | } |
||
18 | |||
19 | protected function getRequestTag(): string |
||
20 | { |
||
21 | return dechex(microtime(true) * 1000000); |
||
22 | } |
||
23 | } |
||
24 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: