Skip to content

Commit

Permalink
优化函数调用
Browse files Browse the repository at this point in the history
  • Loading branch information
toxmc committed May 20, 2020
1 parent d9c23a3 commit 5bb591f
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/Server/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Application
/**
* load laravel Application.
*
* @var \Illuminate\Container\Container
* @var Container
*/

protected static $loadApplication = null;
Expand All @@ -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;

Expand All @@ -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.
*
Expand Down Expand Up @@ -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()
{
Expand All @@ -108,7 +121,7 @@ public function getApplication()
/**
* Load application.
*
* @return \Illuminate\Contracts\Foundation\Application
* @return Container
*/
protected function loadApplication()
{
Expand All @@ -119,8 +132,8 @@ protected function loadApplication()
}

/**
* @return Kernel
* @throws
* @return \Illuminate\Contracts\Http\Kernel
*/
public function kernel()
{
Expand All @@ -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信息
Expand Down

0 comments on commit 5bb591f

Please sign in to comment.