Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HowTo] Call App::dispatchRouterAndPrepareRoute() inside an app middleware ? #1905

Closed
wollanup opened this issue Jun 6, 2016 · 4 comments
Closed

Comments

@wollanup
Copy link

wollanup commented Jun 6, 2016

Here is the process I would follow :

$app->add('authorization');
$app->add('authentication');
... another middleware to remove content extension from URI(.json, .xml...) ...
$app->add(Middleware::formatNegotiator());
$app->add(Middleware::trailingSlash());

My last Middleware "authorization" is ACL service based on routes Names, so it requires 'determineRouteBeforeAppMiddleware' => true, in config.

But if I determine routes before a call to my middlewares, it can't work. e.g :
URI : GET /api/resource/list.json/
Route : $app->get('/resource/list')
URI doesn't match my route pattern.

The workaround I currently use is to execute code inside Slim\App::dispatchRouterAndPrepareRoute() protected method as a last middleware before Authentification, but maybe there could be a cleaner way to do this without duplication of code or Slim\App class extend.
Any thoughts about this ?

@akrabat
Copy link
Member

akrabat commented Jun 6, 2016

Extending App is the way to do this at the moment. I expect that in 4.0 we'll convert the route determination logic to middleware so that you can put middleware before and after it.

@wollanup
Copy link
Author

wollanup commented Jun 6, 2016

OK, thank you for your fast answer, I'll wait for 4.0

@designermonkey
Copy link
Member

@akrabat, anywhere for this to be logged as a requested feature, so it doesn't get missed?

@akrabat
Copy link
Member

akrabat commented Jan 8, 2017

This is logged in #1686 as:

Remove determineRouteBeforeDispatch and make routing a middleware that can be placed where you want it to be. If you don't add it yourself, we would add it immediately before dispatch.

@akrabat akrabat closed this as completed Jan 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants