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

Adding support for middleware arguments. #1

Open
kafkiansky opened this issue Jan 15, 2022 · 0 comments
Open

Adding support for middleware arguments. #1

kafkiansky opened this issue Jan 15, 2022 · 0 comments

Comments

@kafkiansky
Copy link
Owner

kafkiansky commented Jan 15, 2022

Now there is no possibility to use arguments with middleware as, for example, in Laravel.

As I imagine it, the arguments can be specified as an array within the attribute:

#[Middleware([MiddlewareA::class => ['x' => 1, 'y' => 2]])]
final class SomeController
{
}

Inside the middleware MiddlewareA arguments can be accessed using ServerRequestInterface::getAttribute() with middleware fqcn as attribute name:

final class MiddlewareA implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        var_dump($request->getAttribute(MiddlewareA::class)); // ['x' => 1, 'y' => 2];
    }
}

I'm also thinking of adding the ability to refer to symfony parameters with %parameter_name%.

#[Middleware([MiddlewareA::class => ['env' => '%app.env%']])]
final class SomeController
{
}

Then the arguments get to the MiddlewareA, they will be resolved.

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