mirror of
https://github.com/flarum/framework.git
synced 2024-12-11 21:43:38 +08: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:
parent
d53a525383
commit
2777162d32
|
@ -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()
|
||||
|
|
|
@ -36,7 +36,7 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||
});
|
||||
|
||||
$this->app->singleton('flarum.api.routes', function () {
|
||||
return $this->getRoutes();
|
||||
return new RouteCollection;
|
||||
});
|
||||
|
||||
$this->app->singleton(ErrorHandler::class, function () {
|
||||
|
@ -64,6 +64,8 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->populateRoutes($this->app->make('flarum.api.routes'));
|
||||
|
||||
$this->registerNotificationSerializers();
|
||||
|
||||
AbstractSerializeController::setContainer($this->app);
|
||||
|
@ -93,14 +95,12 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the API routes.
|
||||
* Populate the API routes.
|
||||
*
|
||||
* @return RouteCollection
|
||||
* @param RouteCollection $routes
|
||||
*/
|
||||
protected function getRoutes()
|
||||
protected function populateRoutes(RouteCollection $routes)
|
||||
{
|
||||
$routes = new RouteCollection;
|
||||
|
||||
$toController = $this->getHandlerGenerator($this->app);
|
||||
|
||||
// Get forum information
|
||||
|
@ -366,7 +366,5 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||
$this->app->make('events')->fire(
|
||||
new ConfigureApiRoutes($routes, $toController)
|
||||
);
|
||||
|
||||
return $routes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||
});
|
||||
|
||||
$this->app->singleton('flarum.forum.routes', function () {
|
||||
return $this->getRoutes();
|
||||
return new RouteCollection;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,8 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->populateRoutes($this->app->make('flarum.forum.routes'));
|
||||
|
||||
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum');
|
||||
|
||||
$this->flushAssetsWhenThemeChanged();
|
||||
|
@ -49,14 +51,12 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the forum 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(
|
||||
|
@ -140,8 +140,6 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||
'default',
|
||||
$toDefaultController
|
||||
);
|
||||
|
||||
return $routes;
|
||||
}
|
||||
|
||||
protected function flushAssetsWhenThemeChanged()
|
||||
|
|
Loading…
Reference in New Issue
Block a user