1
0
mirror of https://github.com/flarum/core.git synced 2025-07-29 04:30:56 +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

@@ -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;
}
}