thephpleague / route

Fast PSR-7 based routing and dispatch component including PSR-15 middleware, built on top of FastRoute.
http://route.thephpleague.com
MIT License
651 stars 126 forks source link

getRoutes() and removeRoute() methods #270

Closed delboy1978uk closed 4 years ago

delboy1978uk commented 4 years ago

If we have routes specified in a vendor package which we would like to disable, it would be nice to be able to get the routes registered via a getRoutes() method, and a removeRoute(Route $route)method to deregister a route.

As an example, imagine a "user" vendor package that has register, login, reset password etc routes, but for a particular site, you don't want people to be able to register an account, so you could remove the route.

https://github.com/thephpleague/route/pull/272

philipobenito commented 4 years ago

I honestly don't see a good use case for this, I'd suggest that a vendor package shouldn't be forcing the router you use or setting the routes for you.

delboy1978uk commented 4 years ago

my framework is truly modular, you can install vendor packages, and by adding that package name to a config file, the framework registers all it needs to the DI container, including any endpoints the module might have. See here for an example https://github.com/delboy1978uk/bone-user/blob/master/src/BoneMvcUserPackage.php#L124-L144

philipobenito commented 4 years ago

what I'd suggest instead is something like service providers that are optional to use, it's not ideal to have a vendor do something that needs to be undone so I don't think we should be making that easy

delboy1978uk commented 4 years ago

Would you be cool with making $this->routes a protected property in that case? That way your lib stays clean and I can extend it

philipobenito commented 4 years ago

It already is 👍

I'll close this and the PR for now, feedback on your other PR, if you want to look at that I'll get a release out tomorrow

delboy1978uk commented 4 years ago

Haha so it is! Okay great! :-P

delboy1978uk commented 4 years ago

I'm not seeing any additional feedback for the other pull requests?

LuanMaik commented 4 years ago

For this use case, I'll suggest you create a middleware to protect some routes.

delboy1978uk commented 3 years ago

@LuanMaik I already have! ;-) Cheers