mirror of
https://github.com/flarum/framework.git
synced 2024-12-04 08:13:39 +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/flysystem": "^1.0.11",
|
||||||
"league/oauth2-client": "~1.0",
|
"league/oauth2-client": "~1.0",
|
||||||
"matthiasmullie/minify": "^1.3",
|
"matthiasmullie/minify": "^1.3",
|
||||||
|
"middlewares/base-path-router": "^0.2.1",
|
||||||
|
"middlewares/request-handler": "^1.2",
|
||||||
"monolog/monolog": "^1.16.0",
|
"monolog/monolog": "^1.16.0",
|
||||||
"nikic/fast-route": "^0.6",
|
"nikic/fast-route": "^0.6",
|
||||||
"oyejorge/less.php": "^1.7",
|
"oyejorge/less.php": "^1.7",
|
||||||
|
|
|
@ -18,8 +18,9 @@ use Flarum\Foundation\Console\CacheClearCommand;
|
||||||
use Flarum\Foundation\Console\InfoCommand;
|
use Flarum\Foundation\Console\InfoCommand;
|
||||||
use Flarum\Http\Middleware\DispatchRoute;
|
use Flarum\Http\Middleware\DispatchRoute;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
|
use Middlewares\BasePathRouter;
|
||||||
|
use Middlewares\RequestHandler;
|
||||||
use Zend\Stratigility\MiddlewarePipe;
|
use Zend\Stratigility\MiddlewarePipe;
|
||||||
use function Zend\Stratigility\path;
|
|
||||||
|
|
||||||
class InstalledApp implements AppInterface
|
class InstalledApp implements AppInterface
|
||||||
{
|
{
|
||||||
|
@ -52,9 +53,14 @@ class InstalledApp implements AppInterface
|
||||||
|
|
||||||
$pipe = new MiddlewarePipe;
|
$pipe = new MiddlewarePipe;
|
||||||
|
|
||||||
$pipe->pipe($this->subPath('api', 'flarum.api.middleware'));
|
$pipe->pipe(
|
||||||
$pipe->pipe($this->subPath('admin', 'flarum.admin.middleware'));
|
new BasePathRouter([
|
||||||
$pipe->pipe($this->subPath('', 'flarum.forum.middleware'));
|
$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;
|
return $pipe;
|
||||||
}
|
}
|
||||||
|
@ -85,12 +91,9 @@ class InstalledApp implements AppInterface
|
||||||
return $pipe;
|
return $pipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function subPath($pathName, $middlewareStack)
|
private function subPath($pathName): string
|
||||||
{
|
{
|
||||||
return path(
|
return parse_url($this->laravel->url($pathName), PHP_URL_PATH) ?: '/';
|
||||||
parse_url($this->laravel->url($pathName), PHP_URL_PATH) ?: '/',
|
|
||||||
$this->laravel->make($middlewareStack)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user