Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the middleware request attributes does not parsed and filled to the object #32

Closed
roquie opened this issue Nov 4, 2018 · 1 comment

Comments

@roquie
Copy link
Contributor

roquie commented Nov 4, 2018

How to reproduce?

  1. Register middleware with following code:
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);
  1. Register container or callback with route attribute, like /user/{user_id}
  2. Dump the $request->getAttribute('user_id') in the middleware and in the destination controller.
  3. 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? :)

@roquie
Copy link
Contributor Author

roquie commented Nov 7, 2018

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.

@roquie roquie closed this as completed Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant