From 7459afb89e554dded03efec24dfdd2131e7fbf50 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 24 Apr 2016 11:10:39 +0930 Subject: [PATCH] Lazily initialise the Application instance See https://github.com/flarum/core/commit/04aef5814ea3d496a759203c38160f8ad29f620f --- framework/core/src/Foundation/AbstractServer.php | 8 ++++++-- framework/core/src/Http/AbstractServer.php | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Foundation/AbstractServer.php b/framework/core/src/Foundation/AbstractServer.php index 091166eb6..5f6115029 100644 --- a/framework/core/src/Foundation/AbstractServer.php +++ b/framework/core/src/Foundation/AbstractServer.php @@ -62,8 +62,6 @@ abstract class AbstractServer if (file_exists($file = $this->basePath.'/config.php')) { $this->config = include $file; } - - $this->app = $this->getApp(); } /** @@ -135,6 +133,10 @@ abstract class AbstractServer */ protected function getApp() { + if ($this->app !== null) { + return $this->app; + } + date_default_timezone_set('UTC'); $app = new Application($this->basePath, $this->publicPath); @@ -182,6 +184,8 @@ abstract class AbstractServer $app->boot(); + $this->app = $app; + return $app; } diff --git a/framework/core/src/Http/AbstractServer.php b/framework/core/src/Http/AbstractServer.php index dc72b154e..cb82741fc 100644 --- a/framework/core/src/Http/AbstractServer.php +++ b/framework/core/src/Http/AbstractServer.php @@ -44,9 +44,11 @@ abstract class AbstractServer extends BaseAbstractServer */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null) { - $this->collectGarbage($this->app); + $app = $this->getApp(); - $middleware = $this->getMiddleware($this->app); + $this->collectGarbage($app); + + $middleware = $this->getMiddleware($app); return $middleware($request, $response, $out); }