igniphp / framework

Swoole, PSR-15, PSR-7, PSR-11 lightweight modular anti-framework for REST micro-services.
MIT License
265 stars 14 forks source link

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

Closed roquie closed 5 years ago

roquie commented 5 years ago

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);



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? :)
roquie commented 5 years ago

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.