class Test implements \Psr\Http\Server\MiddlewareInterface {
/**
* Process an incoming server request and return a response, optionally delegating
* response creation to a handler.
*/
public function process(
\Psr\Http\Message\ServerRequestInterface $request,
\Psr\Http\Server\RequestHandlerInterface $handler
): \Psr\Http\Message\ResponseInterface {
dump($request->getAttribute('user_id'));
return $handler->handle($request);
}
};
$app->use(Test::class);
2. Register container or callback with route attribute, like `/user/{user_id}`
4. Dump the `$request->getAttribute('user_id')` in the middleware and in the destination controller.
5. Run it.
Attribute `user_id` allows use only in the controller handler (`__invoke`). In the middleware attribute value will be equals `null`.
This is a bug or feature? :)
How I can validate incoming route attributes? :)
Request attributes does not passing here, but it no need for me any more. Validation of route attributes moved to controller __invoke because validation rules in most cases unique for each case.
How to reproduce?
Register middleware with following code:
$app->use(Test::class);