1
0
mirror of https://github.com/flarum/core.git synced 2025-08-01 22:20:21 +02:00

Revamp routing

All routes are now stored in a RouteCollection, which is then used
for dispatching by the (reusable) RouterMiddleware.

This change also entails moving all routes to the service providers.
This may be changed again later, and is done for convenience reasons
right now.
This commit is contained in:
Franz Liedke
2015-06-17 00:16:35 +02:00
parent b65d18ee7f
commit 33d663bc8e
12 changed files with 542 additions and 359 deletions

View File

@@ -1,10 +1,32 @@
<?php namespace Flarum\Forum;
use Illuminate\Support\ServiceProvider;
use Flarum\Http\RouteCollection;
use Flarum\Http\UrlGenerator;
use Flarum\Support\AssetManager;
use Illuminate\Support\ServiceProvider;
use Psr\Http\Message\ServerRequestInterface;
class ForumServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('flarum.forum.assetManager', function ($app) {
return new AssetManager($app['files'], $app['path.public'].'/assets', 'forum');
});
$this->app->singleton(
'Flarum\Http\UrlGeneratorInterface',
function () {
return new UrlGenerator($this->app->make('flarum.forum.routes'));
}
);
}
/**
* Bootstrap the application events.
*
@@ -20,18 +42,60 @@ class ForumServiceProvider extends ServiceProvider
$root.'/public/fonts' => public_path('assets/fonts')
]);
include __DIR__.'/routes.php';
$this->routes();
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
protected function routes()
{
$this->app['flarum.forum.assetManager'] = $this->app->share(function ($app) {
return new AssetManager($app['files'], $app['path.public'].'/assets', 'forum');
});
$this->app->instance('flarum.forum.routes', $routes = new RouteCollection);
/**
* Route::group(['middleware' => 'Flarum\Forum\Middleware\LoginWithCookie'], function () use ($action) {
* For the two below
*/
$routes->get(
'/',
'flarum.forum.index',
$this->action('Flarum\Forum\Actions\IndexAction')
);
$routes->get(
'/logout',
'flarum.forum.logout',
$this->action('Flarum\Forum\Actions\LogoutAction')
);
$routes->post(
'/login',
'flarum.forum.login',
$this->action('Flarum\Forum\Actions\LoginAction')
);
$routes->get(
'/confirm/{token}',
'flarum.forum.confirmEmail',
$this->action('Flarum\Forum\Actions\ConfirmEmailAction')
);
$routes->get(
'/reset/{token}',
'flarum.forum.resetPassword',
$this->action('Flarum\Forum\Actions\ResetPasswordAction')
);
$routes->post(
'/reset',
'flarum.forum.savePassword',
$this->action('Flarum\Forum\Actions\SavePasswordAction')
);
}
protected function action($class)
{
return function (ServerRequestInterface $httpRequest, $routeParams) use ($class) {
$action = $this->app->make($class);
return $action->handle($httpRequest, $routeParams);
};
}
}