mirror of
https://github.com/flarum/framework.git
synced 2024-12-03 15:43:59 +08:00
Load middleware stacks lazily
This way, the forum middleware does not need to be loaded for API requests, and vice-versa.
This commit is contained in:
parent
02f27b0fa1
commit
31480dd1ed
|
@ -44,6 +44,8 @@
|
|||
"league/flysystem": "^1.0.11",
|
||||
"league/oauth2-client": "~1.0",
|
||||
"matthiasmullie/minify": "^1.3",
|
||||
"middlewares/base-path-router": "^0.2.1",
|
||||
"middlewares/request-handler": "^1.2",
|
||||
"monolog/monolog": "^1.16.0",
|
||||
"nikic/fast-route": "^0.6",
|
||||
"oyejorge/less.php": "^1.7",
|
||||
|
|
|
@ -18,8 +18,9 @@ use Flarum\Foundation\Console\CacheClearCommand;
|
|||
use Flarum\Foundation\Console\InfoCommand;
|
||||
use Flarum\Http\Middleware\DispatchRoute;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Middlewares\BasePathRouter;
|
||||
use Middlewares\RequestHandler;
|
||||
use Zend\Stratigility\MiddlewarePipe;
|
||||
use function Zend\Stratigility\path;
|
||||
|
||||
class InstalledApp implements AppInterface
|
||||
{
|
||||
|
@ -52,9 +53,14 @@ class InstalledApp implements AppInterface
|
|||
|
||||
$pipe = new MiddlewarePipe;
|
||||
|
||||
$pipe->pipe($this->subPath('api', 'flarum.api.middleware'));
|
||||
$pipe->pipe($this->subPath('admin', 'flarum.admin.middleware'));
|
||||
$pipe->pipe($this->subPath('', 'flarum.forum.middleware'));
|
||||
$pipe->pipe(
|
||||
new BasePathRouter([
|
||||
$this->subPath('api') => 'flarum.api.middleware',
|
||||
$this->subPath('admin') => 'flarum.admin.middleware',
|
||||
$this->subPath('') => 'flarum.forum.middleware',
|
||||
])
|
||||
);
|
||||
$pipe->pipe(new RequestHandler($this->laravel));
|
||||
|
||||
return $pipe;
|
||||
}
|
||||
|
@ -85,12 +91,9 @@ class InstalledApp implements AppInterface
|
|||
return $pipe;
|
||||
}
|
||||
|
||||
private function subPath($pathName, $middlewareStack)
|
||||
private function subPath($pathName): string
|
||||
{
|
||||
return path(
|
||||
parse_url($this->laravel->url($pathName), PHP_URL_PATH) ?: '/',
|
||||
$this->laravel->make($middlewareStack)
|
||||
);
|
||||
return parse_url($this->laravel->url($pathName), PHP_URL_PATH) ?: '/';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user