mirror of
https://github.com/flarum/core.git
synced 2025-01-18 06:38:25 +01:00
Pass container into apps, adapt path matching
This commit is contained in:
parent
869ec54bd0
commit
2d4dc02ca1
@ -44,6 +44,7 @@
|
||||
"league/flysystem": "^1.0.11",
|
||||
"league/oauth2-client": "~1.0",
|
||||
"matthiasmullie/minify": "^1.3",
|
||||
"middlewares/base-path": "^1.1",
|
||||
"middlewares/base-path-router": "^0.2.1",
|
||||
"middlewares/request-handler": "^1.2",
|
||||
"monolog/monolog": "^1.16.0",
|
||||
|
@ -18,6 +18,8 @@ use Flarum\Foundation\Console\CacheClearCommand;
|
||||
use Flarum\Foundation\Console\InfoCommand;
|
||||
use Flarum\Http\Middleware\DispatchRoute;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Middlewares\BasePath;
|
||||
use Middlewares\BasePathRouter;
|
||||
use Middlewares\RequestHandler;
|
||||
use Zend\Stratigility\MiddlewarePipe;
|
||||
@ -25,18 +27,18 @@ use Zend\Stratigility\MiddlewarePipe;
|
||||
class InstalledApp implements AppInterface
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
* @var Container
|
||||
*/
|
||||
protected $laravel;
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
public function __construct(Application $laravel, array $config)
|
||||
public function __construct(Container $container, array $config)
|
||||
{
|
||||
$this->laravel = $laravel;
|
||||
$this->container = $container;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
@ -53,14 +55,15 @@ class InstalledApp implements AppInterface
|
||||
|
||||
$pipe = new MiddlewarePipe;
|
||||
|
||||
$pipe->pipe(new BasePath($this->basePath()));
|
||||
$pipe->pipe(
|
||||
new BasePathRouter([
|
||||
$this->subPath('api') => 'flarum.api.middleware',
|
||||
$this->subPath('admin') => 'flarum.admin.middleware',
|
||||
$this->subPath('') => 'flarum.forum.middleware',
|
||||
'/' => 'flarum.forum.middleware',
|
||||
])
|
||||
);
|
||||
$pipe->pipe(new RequestHandler($this->laravel));
|
||||
$pipe->pipe(new RequestHandler($this->container));
|
||||
|
||||
return $pipe;
|
||||
}
|
||||
@ -72,7 +75,7 @@ class InstalledApp implements AppInterface
|
||||
|
||||
private function needsUpdate(): bool
|
||||
{
|
||||
$settings = $this->laravel->make(SettingsRepositoryInterface::class);
|
||||
$settings = $this->container->make(SettingsRepositoryInterface::class);
|
||||
$version = $settings->get('version');
|
||||
|
||||
return $version !== Application::VERSION;
|
||||
@ -85,15 +88,20 @@ class InstalledApp implements AppInterface
|
||||
{
|
||||
$pipe = new MiddlewarePipe;
|
||||
$pipe->pipe(
|
||||
new DispatchRoute($this->laravel->make('flarum.update.routes'))
|
||||
new DispatchRoute($this->container->make('flarum.update.routes'))
|
||||
);
|
||||
|
||||
return $pipe;
|
||||
}
|
||||
|
||||
private function basePath(): string
|
||||
{
|
||||
return parse_url($this->config['url'], PHP_URL_PATH) ?: '/';
|
||||
}
|
||||
|
||||
private function subPath($pathName): string
|
||||
{
|
||||
return parse_url($this->laravel->url($pathName), PHP_URL_PATH) ?: '/';
|
||||
return '/'.$this->config['paths'][$pathName];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,11 +110,11 @@ class InstalledApp implements AppInterface
|
||||
public function getConsoleCommands()
|
||||
{
|
||||
return [
|
||||
$this->laravel->make(GenerateMigrationCommand::class),
|
||||
$this->laravel->make(InfoCommand::class, ['config' => $this->config]),
|
||||
$this->laravel->make(MigrateCommand::class),
|
||||
$this->laravel->make(ResetCommand::class),
|
||||
$this->laravel->make(CacheClearCommand::class),
|
||||
$this->container->make(GenerateMigrationCommand::class),
|
||||
$this->container->make(InfoCommand::class, ['config' => $this->config]),
|
||||
$this->container->make(MigrateCommand::class),
|
||||
$this->container->make(ResetCommand::class),
|
||||
$this->container->make(CacheClearCommand::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -12,23 +12,23 @@
|
||||
namespace Flarum\Install;
|
||||
|
||||
use Flarum\Foundation\AppInterface;
|
||||
use Flarum\Foundation\Application;
|
||||
use Flarum\Http\Middleware\DispatchRoute;
|
||||
use Flarum\Http\Middleware\HandleErrorsWithWhoops;
|
||||
use Flarum\Http\Middleware\StartSession;
|
||||
use Flarum\Install\Console\InstallCommand;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Zend\Stratigility\MiddlewarePipe;
|
||||
|
||||
class Installer implements AppInterface
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
* @var Container
|
||||
*/
|
||||
protected $laravel;
|
||||
protected $container;
|
||||
|
||||
public function __construct(Application $laravel)
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->laravel = $laravel;
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,10 +37,10 @@ class Installer implements AppInterface
|
||||
public function getRequestHandler()
|
||||
{
|
||||
$pipe = new MiddlewarePipe;
|
||||
$pipe->pipe($this->laravel->make(HandleErrorsWithWhoops::class));
|
||||
$pipe->pipe($this->laravel->make(StartSession::class));
|
||||
$pipe->pipe($this->container->make(HandleErrorsWithWhoops::class));
|
||||
$pipe->pipe($this->container->make(StartSession::class));
|
||||
$pipe->pipe(
|
||||
new DispatchRoute($this->laravel->make('flarum.install.routes'))
|
||||
new DispatchRoute($this->container->make('flarum.install.routes'))
|
||||
);
|
||||
|
||||
return $pipe;
|
||||
@ -52,7 +52,7 @@ class Installer implements AppInterface
|
||||
public function getConsoleCommands()
|
||||
{
|
||||
return [
|
||||
$this->laravel->make(InstallCommand::class),
|
||||
$this->container->make(InstallCommand::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user