middlewares / ideas

Need a Middleware or looking for ideas?
5 stars 0 forks source link

league/route #15

Open oscarotero opened 7 years ago

oscarotero commented 7 years ago

Not sure about this, due league/route uses a double pass signature and PSR-15 has a single pass, so it is incompatible with other router sytems like aura.router and fastroute. Anyway, a PSR-15 wrapper could be useful, creating the response before execute the route handler.

itsjavi commented 7 years ago

This is my approach, not perfect though because it does not fully support request-handler (e.g. arguments injection in the callback) and it still uses double pass internally.

https://github.com/itsjavi/flatdown/blob/feature/leagueroute-ps15support/app/Middlewares/LeagueRoute/LeagueRoute.php

oscarotero commented 7 years ago

Other approach could be create a strategy to use the same signature than fast-route and aura-router middleware: https://github.com/thephpleague/route/blob/master/src/Strategy/ApplicationStrategy.php#L21

itsjavi commented 7 years ago

I wrote a prototype of your suggestion and it works pretty good so far, the only thing is that I had to reproduce the\League\Route\RouteCollection::dispatch() and \League\Route\Middleware\ExecutionChain::buildExecutionChain() methods internally in order to make it compatible: https://github.com/itsjavi/flatdown/blob/feature/leagueroute-ps15support/app/Middlewares/LeagueRoute/LeagueRoute.php#L97

This is the only way I found to keep it compatible with both League Router and PSR-15 callable signatures as well as with the request-handler argument injection at the end.

oscarotero commented 7 years ago

Looks better, but maybe a bit "hacky". I didn't realize that league/route is not only a router but also a middleware dispatcher. And these middlewares have the double pass signature, so although we can fix the request handler to be compatible with psr-15, the middleware stack of the route keeps having the old signature. And all this things, with the addition of having a container to the dependency injection, makes this package more than a simple router but almost a framework. Forcing the package to work like a more simple PSR-15 router makes it lose some of its features.

Not sure what to do

itsjavi commented 7 years ago

Seems very hacky indeed, I opened a feature request in the project, but I think we'll have to wait until the final PSR-15 approval. Meanwhile if we still want to support this router, we'll have to sacrifice some goodies as you said.

lukewatts commented 2 years ago

https://github.com/thephpleague/route/issues/167