From 04aef5814ea3d496a759203c38160f8ad29f620f Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 16 Apr 2016 13:07:52 +0900 Subject: [PATCH] AbstractServer: Store app instance as class property This will make it easier to reuse the instance in an asynchronous setting (e.g. ReactPHP), where one application instance is preloaded and reused for each incoming request. --- framework/core/src/Foundation/AbstractServer.php | 7 +++++++ framework/core/src/Http/AbstractServer.php | 6 ++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Foundation/AbstractServer.php b/framework/core/src/Foundation/AbstractServer.php index e6f559155..a37d4ec28 100644 --- a/framework/core/src/Foundation/AbstractServer.php +++ b/framework/core/src/Foundation/AbstractServer.php @@ -17,6 +17,11 @@ use Monolog\Logger; abstract class AbstractServer { + /** + * @var Application + */ + protected $app; + /** * @var string */ @@ -41,6 +46,8 @@ abstract class AbstractServer if (file_exists($file = $this->path.'/config.php')) { $this->config = include $file; } + + $this->app = $this->getApp(); } /** diff --git a/framework/core/src/Http/AbstractServer.php b/framework/core/src/Http/AbstractServer.php index ea69af959..58cc9e8c2 100644 --- a/framework/core/src/Http/AbstractServer.php +++ b/framework/core/src/Http/AbstractServer.php @@ -22,12 +22,10 @@ abstract class AbstractServer extends BaseAbstractServer { public function listen() { - $app = $this->getApp(); - - $this->collectGarbage($app); + $this->collectGarbage($this->app); $server = Server::createServer( - $this->getMiddleware($app), + $this->getMiddleware($this->app), $_SERVER, $_GET, $_POST,