silexphp / Silex

[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components
https://silex.symfony.com
MIT License
3.58k stars 718 forks source link

Add routes in $app->before(function) #994

Closed mmuruev closed 9 years ago

mmuruev commented 10 years ago

Seems that code like this

$app->before(function($request) use ($app){ $app->mount('/dynamic', new DynamicLoadController()); }, \Silex\Application::EARLY_EVENT); Have no effect on router. But by doc this code should run before security and route. Is this a bug?

henrikbjorn commented 10 years ago

At this point the routes have already been "flushed" i think instead you could do it in a boot method in a service provider.

mmuruev commented 10 years ago

But not chance to update routes? If it so early event why not?

henrikbjorn commented 10 years ago

https://github.com/silexphp/Silex/blob/master/src/Silex/Application.php#L519 you can see it calls flush at that point, that is before the handle method i called, that means its before any events gets notified.

mmuruev commented 10 years ago

Acctualy I've found that Silex routes perfectly work, for me.. only issue was in REST provider. But all requiest without additional provider work. Seems like this is an external lib issue. And without it you can easy update your routes without tricky things.