izniburak / php-router

PHP Router, which also has rich features like Middlewares and Controllers is simple, useful and flexible router class for PHP.
https://github.com/izniburak/php-router/wiki
MIT License
238 stars 45 forks source link

send current route to middleware #45

Closed NeftaliAcosta closed 2 years ago

NeftaliAcosta commented 3 years ago

I am making a modular site:

Each module has its own group path with its respective middleware. For example.

$this-> route-> group ('/ panel/user', function ($ r) {
 #code here
}, ['before' => 'sessionMiddleware']); 

$this-> route-> group ('/ panel/galerry', function ($ r) {
 #code here
}, ['before' => 'sessionMiddleware']); 

How can I go about sending the current route as a parameter to the middleware?

For example. With the same middleware you can validate that the user has access to the gallery group, but not to the users group.

If this is not possible, can you recommend a viable option please?

Thanks guys.

izniburak commented 3 years ago

Hi, There is no way directly right now. But you can use Symfony HTTP Component that comes with the Router when you install the Router package. This component has a lot of useful methods in order to get current path or full path of the active Route.

Also, I'm thinking of add a new functionality for that. I will work on this.

Thanks.

NeftaliAcosta commented 3 years ago

Thank you for considering this functionality in the future.

Regarding Symfony HTTP, would it be too much trouble if you share a basic example with me please?

Thanks.