From 927e4ca3edf8db0eb9d512bc84fe29728c7c3f53 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 24 Jun 2017 12:08:04 +0200 Subject: [PATCH] Restructure Flarum\Forum namespace --- src/Forum/ForumServiceProvider.php | 73 ++--------------------- src/Forum/{WebApp.php => Frontend.php} | 0 src/Forum/routes.php | 82 ++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 67 deletions(-) rename src/Forum/{WebApp.php => Frontend.php} (100%) create mode 100644 src/Forum/routes.php diff --git a/src/Forum/ForumServiceProvider.php b/src/Forum/ForumServiceProvider.php index 4c1fa33f7..86ef67d31 100644 --- a/src/Forum/ForumServiceProvider.php +++ b/src/Forum/ForumServiceProvider.php @@ -56,82 +56,21 @@ class ForumServiceProvider extends AbstractServiceProvider */ protected function populateRoutes(RouteCollection $routes) { - $route = $this->app->make(RouteHandlerFactory::class); + $factory = $this->app->make(RouteHandlerFactory::class); - $routes->get( - '/all', - 'index', - $toDefaultController = $route->toController(Controller\IndexController::class) - ); - - $routes->get( - '/d/{id:\d+(?:-[^/]*)?}[/{near:[^/]*}]', - 'discussion', - $route->toController(Controller\DiscussionController::class) - ); - - $routes->get( - '/u/{username}[/{filter:[^/]*}]', - 'user', - $route->toController(Controller\FrontendController::class) - ); - - $routes->get( - '/settings', - 'settings', - $route->toController(Controller\AuthorizedWebAppController::class) - ); - - $routes->get( - '/notifications', - 'notifications', - $route->toController(Controller\AuthorizedWebAppController::class) - ); - - $routes->get( - '/logout', - 'logout', - $route->toController(Controller\LogOutController::class) - ); - - $routes->post( - '/login', - 'login', - $route->toController(Controller\LogInController::class) - ); - - $routes->post( - '/register', - 'register', - $route->toController(Controller\RegisterController::class) - ); - - $routes->get( - '/confirm/{token}', - 'confirmEmail', - $route->toController(Controller\ConfirmEmailController::class) - ); - - $routes->get( - '/reset/{token}', - 'resetPassword', - $route->toController(Controller\ResetPasswordController::class) - ); - - $routes->post( - '/reset', - 'savePassword', - $route->toController(Controller\SavePasswordController::class) - ); + $callback = include __DIR__.'/routes.php'; + $callback($routes, $factory); $this->app->make('events')->fire( - new ConfigureForumRoutes($routes, $route) + new ConfigureForumRoutes($routes, $factory) ); $defaultRoute = $this->app->make('flarum.settings')->get('default_route'); if (isset($routes->getRouteData()[0]['GET'][$defaultRoute])) { $toDefaultController = $routes->getRouteData()[0]['GET'][$defaultRoute]; + } else { + $toDefaultController = $factory->toController(Controller\IndexController::class); } $routes->get( diff --git a/src/Forum/WebApp.php b/src/Forum/Frontend.php similarity index 100% rename from src/Forum/WebApp.php rename to src/Forum/Frontend.php diff --git a/src/Forum/routes.php b/src/Forum/routes.php new file mode 100644 index 000000000..96e26dc3a --- /dev/null +++ b/src/Forum/routes.php @@ -0,0 +1,82 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Forum\Controller; +use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteCollection; + +return function (RouteCollection $map, RouteHandlerFactory $route) { + $map->get( + '/all', + 'index', + $route->toController(Controller\IndexController::class) + ); + + $map->get( + '/d/{id:\d+(?:-[^/]*)?}[/{near:[^/]*}]', + 'discussion', + $route->toController(Controller\DiscussionController::class) + ); + + $map->get( + '/u/{username}[/{filter:[^/]*}]', + 'user', + $route->toController(Controller\FrontendController::class) + ); + + $map->get( + '/settings', + 'settings', + $route->toController(Controller\AuthorizedWebAppController::class) + ); + + $map->get( + '/notifications', + 'notifications', + $route->toController(Controller\AuthorizedWebAppController::class) + ); + + $map->get( + '/logout', + 'logout', + $route->toController(Controller\LogOutController::class) + ); + + $map->post( + '/login', + 'login', + $route->toController(Controller\LogInController::class) + ); + + $map->post( + '/register', + 'register', + $route->toController(Controller\RegisterController::class) + ); + + $map->get( + '/confirm/{token}', + 'confirmEmail', + $route->toController(Controller\ConfirmEmailController::class) + ); + + $map->get( + '/reset/{token}', + 'resetPassword', + $route->toController(Controller\ResetPasswordController::class) + ); + + $map->post( + '/reset', + 'savePassword', + $route->toController(Controller\SavePasswordController::class) + ); +};