From d35532b7443afa498f4ffeec0eaa3ccb8f89c065 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 21 Sep 2018 23:30:14 +0200 Subject: [PATCH] Boot Flarum app in Server classes This is in preparation for fixing #1421 - it allows us to encapsulate the exception handling in the server classes, so that we can keep the skeleton (flarum/flarum) lean. --- framework/core/src/Console/Server.php | 11 +++++++---- framework/core/src/Http/Server.php | 12 +++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/framework/core/src/Console/Server.php b/framework/core/src/Console/Server.php index a65ef9b28..d55e14dba 100644 --- a/framework/core/src/Console/Server.php +++ b/framework/core/src/Console/Server.php @@ -13,23 +13,26 @@ namespace Flarum\Console; use Flarum\Console\Event\Configuring; use Flarum\Foundation\Application; +use Flarum\Foundation\SiteInterface; use Illuminate\Contracts\Events\Dispatcher; use Symfony\Component\Console\Application as ConsoleApplication; class Server { - protected $commands; + private $site; - public function __construct(array $commands) + public function __construct(SiteInterface $site) { - $this->commands = $commands; + $this->site = $site; } public function listen() { + $app = $this->site->bootApp(); + $console = new ConsoleApplication('Flarum', Application::VERSION); - foreach ($this->commands as $command) { + foreach ($app->getConsoleCommands() as $command) { $console->add($command); } diff --git a/framework/core/src/Http/Server.php b/framework/core/src/Http/Server.php index 6c24afba6..9c9e36ee8 100644 --- a/framework/core/src/Http/Server.php +++ b/framework/core/src/Http/Server.php @@ -11,7 +11,7 @@ namespace Flarum\Http; -use Psr\Http\Server\RequestHandlerInterface; +use Flarum\Foundation\SiteInterface; use Throwable; use Zend\Diactoros\Response; use Zend\Diactoros\ServerRequest; @@ -22,17 +22,19 @@ use Zend\Stratigility\Middleware\ErrorResponseGenerator; class Server { - protected $requestHandler; + private $site; - public function __construct(RequestHandlerInterface $requestHandler) + public function __construct(SiteInterface $site) { - $this->requestHandler = $requestHandler; + $this->site = $site; } public function listen() { + $app = $this->site->bootApp(); + $runner = new RequestHandlerRunner( - $this->requestHandler, + $app->getRequestHandler(), new SapiEmitter, [ServerRequestFactory::class, 'fromGlobals'], function (Throwable $e) {