jshannon63 / laravel-psr15-middleware

Use your PSR-15 compliant middleware in Laravel
MIT License
13 stars 5 forks source link

Feature/route attributes #3

Closed dandjo closed 6 years ago

dandjo commented 6 years ago

Hey Jim, I added the possibility to use middleware arguments in routes. They are passed to the middleware constructor. You can then use:

config/psr15middleware.php

return [
    'aliases' => [
        'example' => App\Http\Middleware\Psr15\Example::class,
    ]
];

routes/web.php

Route::get('foobar', function() {
    return 'Hi Jim!';
})->middleware('example:first,second');

Http/Middleware/Psr15/Example.php

class Example implements MiddlewareInterface
{
    public function __construct($argument1 = null, $argument2 = null)
    {
        $this->argument1 = $argument1;
        $this->argument2 = $argument2;
    }

    public function process(ServerRequestInterface $request,
                            RequestHandlerInterface $handler): ResponseInterface
    {
        // do something with arguments
    }
}

Feel free to optimize the implementation. Kind regards. Daniel

jshannon63 commented 6 years ago

I like this, but currently not getting parameters passed by kernel. Have you got this working at your end ok?

jshannon63 commented 6 years ago

Actually just got it working. I will prepare a similar method and PR for discussion. Thanks again!

jshannon63 commented 6 years ago

Please check PR #4 for an alternative approach to your PR. Please let me know what you think

jshannon63 commented 6 years ago

See PR #4