mirror of
https://github.com/flarum/framework.git
synced 2025-05-31 12:35:48 +08: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:
@ -1,10 +1,32 @@
|
||||
<?php namespace Flarum\Admin;
|
||||
|
||||
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 AdminServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('flarum.admin.assetManager', function () {
|
||||
return new AssetManager($this->app->make('files'), public_path('assets'), 'admin');
|
||||
});
|
||||
|
||||
$this->app->singleton(
|
||||
'Flarum\Http\UrlGeneratorInterface',
|
||||
function () {
|
||||
return new UrlGenerator($this->app->make('flarum.admin.routes'));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
@ -20,18 +42,26 @@ class AdminServiceProvider 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->singleton('flarum.admin.assetManager', function () {
|
||||
return new AssetManager($this->app->make('files'), public_path('assets'), 'admin');
|
||||
});
|
||||
$this->app->instance('flarum.admin.routes', $routes = new RouteCollection);
|
||||
|
||||
$routes->get(
|
||||
'/',
|
||||
'flarum.admin.index',
|
||||
$this->action('Flarum\Admin\Actions\IndexAction')
|
||||
);
|
||||
}
|
||||
|
||||
protected function action($class)
|
||||
{
|
||||
return function (ServerRequestInterface $httpRequest, $routeParams) use ($class) {
|
||||
$action = $this->app->make($class);
|
||||
|
||||
return $action->handle($httpRequest, $routeParams);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
$action = function ($class) {
|
||||
return function (ServerRequestInterface $httpRequest, $routeParams) use ($class) {
|
||||
$action = $this->app->make($class);
|
||||
|
||||
return $action->handle($httpRequest, $routeParams);
|
||||
};
|
||||
};
|
||||
|
||||
/** @var Flarum\Http\Router $router */
|
||||
$router = $this->app->make('Flarum\Http\Router');
|
||||
|
||||
$router->get('/admin', 'flarum.admin.index', $action('Flarum\Admin\Actions\IndexAction'));
|
Reference in New Issue
Block a user