1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 07:24:27 +02:00

Ensure routes are only populated after extensions have registered listeners

Because extensions can have dependencies injected, a RouteCollection could potentially be instantiated, and thus the ConfigureRoutes event would be called before extensions have had a chance to subscribe to it. Instead, we instantiate the RouteCollection on demand, but only populate it when the application boots.
This commit is contained in:
Toby Zerner
2016-01-02 15:03:11 +10:30
parent e86cc39f5b
commit ff0ce09620
3 changed files with 18 additions and 24 deletions

View File

@@ -33,7 +33,7 @@ class AdminServiceProvider extends AbstractServiceProvider
});
$this->app->singleton('flarum.admin.routes', function () {
return $this->getRoutes();
return new RouteCollection;
});
}
@@ -42,6 +42,8 @@ class AdminServiceProvider extends AbstractServiceProvider
*/
public function boot()
{
$this->populateRoutes($this->app->make('flarum.admin.routes'));
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum.admin');
$this->flushAssetsWhenThemeChanged();
@@ -50,14 +52,12 @@ class AdminServiceProvider extends AbstractServiceProvider
}
/**
* Register the admin client routes.
* Populate the forum client routes.
*
* @return RouteCollection
* @param RouteCollection $routes
*/
protected function getRoutes()
protected function populateRoutes(RouteCollection $routes)
{
$routes = new RouteCollection;
$toController = $this->getHandlerGenerator($this->app);
$routes->get(
@@ -65,8 +65,6 @@ class AdminServiceProvider extends AbstractServiceProvider
'index',
$toController('Flarum\Admin\Controller\ClientController')
);
return $routes;
}
protected function flushAssetsWhenThemeChanged()