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

Extract Flarum\Foundation\Site class

This class holds all information relevant to a local Flarum site,
such as paths and local configuration. From this information, it
is able to instantiate a Flarum\Foundation\Application instance,
which represents a Flarum installation's runtime.

This will also be useful for setting up e.g. multi-tenant
environments.
This commit is contained in:
Franz Liedke
2017-07-02 13:30:02 +02:00
parent 051bb5acb8
commit e46b3d54d1
4 changed files with 143 additions and 123 deletions

View File

@@ -13,14 +13,30 @@ namespace Flarum\Console;
use Flarum\Database\Console\GenerateMigrationCommand;
use Flarum\Database\Console\MigrateCommand;
use Flarum\Foundation\AbstractServer;
use Flarum\Foundation\Application;
use Flarum\Foundation\Console\CacheClearCommand;
use Flarum\Foundation\Console\InfoCommand;
use Flarum\Foundation\Site;
use Flarum\Install\Console\InstallCommand;
use Symfony\Component\Console\Application;
use Flarum\Install\InstallServiceProvider;
use Symfony\Component\Console\Application as ConsoleApplication;
class Server extends AbstractServer
class Server
{
/**
* @param Site $site
* @return Server
*/
public static function fromSite(Site $site)
{
return new static($site->boot());
}
public function __construct(Application $app)
{
$this->app = $app;
}
public function listen()
{
$console = $this->getConsoleApplication();
@@ -29,14 +45,13 @@ class Server extends AbstractServer
}
/**
* @return Application
* @return ConsoleApplication
*/
protected function getConsoleApplication()
{
$app = $this->getApp();
$console = new Application('Flarum', $app->version());
$console = new ConsoleApplication('Flarum', $this->app->version());
$app->register('Flarum\Install\InstallServiceProvider');
$this->app->register(InstallServiceProvider::class);
$commands = [
InstallCommand::class,
@@ -44,7 +59,7 @@ class Server extends AbstractServer
GenerateMigrationCommand::class,
];
if ($app->isInstalled()) {
if ($this->app->isInstalled()) {
$commands = array_merge($commands, [
InfoCommand::class,
CacheClearCommand::class
@@ -52,9 +67,9 @@ class Server extends AbstractServer
}
foreach ($commands as $command) {
$console->add($app->make(
$console->add($this->app->make(
$command,
['config' => $app->isInstalled() ? $app->make('flarum.config') : []]
['config' => $this->app->isInstalled() ? $this->app->make('flarum.config') : []]
));
}