From 5bb591f380902e1f671e92d5debe22a7c79ef234 Mon Sep 17 00:00:00 2001 From: toxmc Date: Wed, 20 May 2020 14:13:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=87=BD=E6=95=B0=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Server/Application.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Server/Application.php b/src/Server/Application.php index 269f74b..9280b03 100644 --- a/src/Server/Application.php +++ b/src/Server/Application.php @@ -17,7 +17,7 @@ class Application /** * load laravel Application. * - * @var \Illuminate\Container\Container + * @var Container */ protected static $loadApplication = null; @@ -38,12 +38,12 @@ class Application /** * Laravel Application. * - * @var \Illuminate\Container\Container + * @var Container */ protected $application; /** - * @var \Illuminate\Contracts\Http\Kernel + * @var Kernel */ protected $kernel; @@ -58,6 +58,16 @@ class Application 'encrypter', 'hash', 'router', 'translator', 'url', 'log' ]; + /** + * @var bool + */ + protected $enableCoroutine = false; + + /** + * @var bool + */ + protected $obOutput = false; + /** * Make an application. * @@ -91,11 +101,14 @@ protected function bootstrap() { $application = $this->getApplication(); $application->bootstrapWith($this->getBootstrappers()); + $this->enableCoroutine = $application->make('config')->get('swoole_http.enable_coroutine', false); + $this->obOutput = $application->make('config')->get('swoole_http.ob_output', true); + $this->preResolveInstances($application); } /** - * @return \Illuminate\Container\Container + * @return Container */ public function getApplication() { @@ -108,7 +121,7 @@ public function getApplication() /** * Load application. * - * @return \Illuminate\Contracts\Foundation\Application + * @return Container */ protected function loadApplication() { @@ -119,8 +132,8 @@ protected function loadApplication() } /** + * @return Kernel * @throws - * @return \Illuminate\Contracts\Http\Kernel */ public function kernel() { @@ -142,18 +155,18 @@ public function getFramework() /** * Run framework. * - * @param \Illuminate\Http\Request $request + * @param Request $request * @return SymfonyResponse * @throws */ public function handle(Request $request) { // 检测是否开启runtime::enableCoroutine - if ($this->application['config']->get('swoole_http.enable_coroutine', false)) { + if ($this->enableCoroutine) { \Swoole\Runtime::enableCoroutine(); } // 检测是否开启ob_output - $this->application['config']->get('swoole_http.ob_output', true) && ob_start(); + $this->obOutput && ob_start(); $response = $this->kernel()->handle($request); // 处理debug信息