You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classTestimplements \Psr\Http\Server\MiddlewareInterface {
/** * Process an incoming server request and return a response, optionally delegating * response creation to a handler. */publicfunctionprocess(
\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);
Register container or callback with route attribute, like /user/{user_id}
Dump the $request->getAttribute('user_id') in the middleware and in the destination controller.
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? :)
The text was updated successfully, but these errors were encountered:
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?
/user/{user_id}
$request->getAttribute('user_id')
in the middleware and in the destination controller.Attribute
user_id
allows use only in the controller handler (__invoke
). In the middleware attribute value will be equalsnull
.This is a bug or feature? :)
How I can validate incoming route attributes? :)
The text was updated successfully, but these errors were encountered: