Skip to content

Commit

Permalink
改进调试输出并去掉一些不必要的类
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Apr 24, 2019
1 parent d1e6015 commit 7f6e6e6
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 346 deletions.
5 changes: 4 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ public function worker($connection)
->setPathinfo($pathinfo)
->withInput($GLOBALS['HTTP_RAW_REQUEST_DATA']);

ob_start();
$response = $this->http->run();
$content = ob_get_clean();

ob_start();

$response->send();
$this->http->end($response);

$content = ob_get_clean() ?: '';
$content .= ob_get_clean() ?: '';

$this->httpResponseCode($response->getCode());

Expand Down
5 changes: 2 additions & 3 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ public function onWorkerStart($worker)
$this->app->workerman = $worker;

$this->app->bind([
'think\Application' => Application::class,
'think\Cookie' => Cookie::class,
'cookie' => Cookie::class,
'think\Cookie' => Cookie::class,
'cookie' => Cookie::class,
]);

if (0 == $worker->id && $this->monitor) {
Expand Down
28 changes: 14 additions & 14 deletions src/command/GatewayWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function execute(Input $input, Output $output)
$port = !empty($option['port']) ? $option['port'] : '2347';
}

$this->start($host, $port, $option);
$this->start($host, (int) $port, $option);
}

/**
Expand All @@ -85,7 +85,7 @@ public function execute(Input $input, Output $output)
* @param array $option 参数
* @return void
*/
public function start($host, $port, $option = [])
public function start(string $host, int $port, array $option = [])
{
$registerAddress = !empty($option['registerAddress']) ? $option['registerAddress'] : '127.0.0.1:1236';

Expand All @@ -97,7 +97,7 @@ public function start($host, $port, $option = [])

// 启动businessWorker
if (!empty($option['businessWorker_deploy'])) {
$this->businessWorker($registerAddress, isset($option['businessWorker']) ? $option['businessWorker'] : []);
$this->businessWorker($registerAddress, $option['businessWorker'] ?? []);
}

// 启动gateway
Expand All @@ -114,7 +114,7 @@ public function start($host, $port, $option = [])
* @param string $registerAddress
* @return void
*/
public function register($registerAddress)
public function register(string $registerAddress)
{
// 初始化register
new Register('text://' . $registerAddress);
Expand All @@ -127,7 +127,7 @@ public function register($registerAddress)
* @param array $option 参数
* @return void
*/
public function businessWorker($registerAddress, $option = [])
public function businessWorker(string $registerAddress, array $option = [])
{
// 初始化 bussinessWorker 进程
$worker = new BusinessWorker();
Expand All @@ -140,13 +140,13 @@ public function businessWorker($registerAddress, $option = [])
/**
* 启动gateway
* @access public
* @param string $registerAddress registerAddress
* @param string $host 服务地址
* @param integer $port 监听端口
* @param array $option 参数
* @param string $registerAddress registerAddress
* @param string $host 服务地址
* @param integer $port 监听端口
* @param array $option 参数
* @return void
*/
public function gateway($registerAddress, $host, $port, $option = [])
public function gateway(string $registerAddress, string $host, int $port, array $option = [])
{
// 初始化 gateway 进程
if (!empty($option['socket'])) {
Expand All @@ -158,7 +158,7 @@ public function gateway($registerAddress, $host, $port, $option = [])
unset($option['host'], $option['port'], $option['protocol']);
}

$gateway = new Gateway($socket, isset($option['context']) ? $option['context'] : []);
$gateway = new Gateway($socket, $option['context'] ?? []);

// 以下设置参数都可以在配置文件中重新定义覆盖
$gateway->name = 'Gateway';
Expand All @@ -184,11 +184,11 @@ public function gateway($registerAddress, $host, $port, $option = [])
/**
* 设置参数
* @access protected
* @param Worker $worker Worker对象
* @param array $option 参数
* @param Worker $worker Worker对象
* @param array $option 参数
* @return void
*/
protected function option($worker, array $option = [])
protected function option(Worker $worker, array $option = [])
{
// 设置参数
if (!empty($option)) {
Expand Down
2 changes: 1 addition & 1 deletion src/command/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function execute(Input $input, Output $output)
Worker::runAll();
}

protected function startServer($class)
protected function startServer(string $class)
{
if (class_exists($class)) {
$worker = new $class;
Expand Down
4 changes: 2 additions & 2 deletions src/command/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function execute(Input $input, Output $output)
$worker->start();
}

protected function getHost($default = '0.0.0.0')
protected function getHost(string $default = '0.0.0.0')
{
if ($this->input->hasOption('host')) {
$host = $this->input->getOption('host');
Expand All @@ -146,7 +146,7 @@ protected function getHost($default = '0.0.0.0')
return $host;
}

protected function getPort($default = '2346')
protected function getPort(string $default = '2346')
{
if ($this->input->hasOption('port')) {
$port = $this->input->getOption('port');
Expand Down
24 changes: 0 additions & 24 deletions src/facade/Application.php

This file was deleted.

25 changes: 0 additions & 25 deletions src/facade/Worker.php

This file was deleted.

Loading

0 comments on commit 7f6e6e6

Please sign in to comment.