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

Group middleware is duplicated #195

Closed Pumpuli closed 6 years ago

Pumpuli commented 6 years ago

Group middleware is added to the middleware stack twice and thus executed twice.

The problem areas seem to be:

  1. When adding routes inside a group (RouteGroup#map()), the group's middleware is added to each route:

https://github.com/thephpleague/route/blob/2320c573fa677f5fd65c40c18acf8c9e8720f9ae/src/RouteGroup.php#L90-L92

  1. When dispatching, the middleware stack is populated from both the route and its group (Dispatcher#setFoundMiddleware()), but since route already contains group middleware, the group middleware gets added a second time:

https://github.com/thephpleague/route/blob/2320c573fa677f5fd65c40c18acf8c9e8720f9ae/src/Dispatcher.php#L80-L85

philipobenito commented 6 years ago

Thanks for the detailed report.

Fixed here https://github.com/thephpleague/route/releases/tag/4.1.1