Skip to content

Commit

Permalink
优化组件的boolean值的判断
Browse files Browse the repository at this point in the history
  • Loading branch information
bingcool committed Feb 14, 2019
1 parent f019a7a commit 4d28764
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion score/Core/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class App extends \Swoolefy\Core\Component {

/**
* $coroutine_id
* @var [type]
* @var null
*/
public $coroutine_id;

Expand Down
11 changes: 4 additions & 7 deletions score/Core/AppTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,17 +572,14 @@ public function redirect(string $url, array $params = [], int $code = 301) {
$query_string = rtrim($query_string,'&');
}
}
// 发送Http跳转,调用此方法会自动end发送并结束响应,2.2.0+版本支持
if(version_compare(swoole_version(), '2.2.0', '>')) {
// 发送Http跳转,调用此方法会自动end发送并结束响应,4.2.0+版本支持
if(version_compare(swoole_version(), '4.2.0', '>')) {
$this->response->redirect($url.$query_string, $code);
return;
}else {
$this->status($code);
$this->response->header('Location', $url.$query_string);
$this->response->end();
return;
}

}

/**
Expand Down Expand Up @@ -624,7 +621,7 @@ public function dump($var, $echo=true, $label=null, $strict=true) {
* asyncHttpClient 简单的模拟http异步并发请求
* @param array $urls
* @param int $timeout 单位ms
* @return
* @return boolean
*/
public function asyncHttpClient(array $urls = [], int $timeout = 500) {
if(!empty($urls)) {
Expand Down Expand Up @@ -936,7 +933,7 @@ public function getClientOS() {
}

/**
* sendHttpStatus,参考tp的
* sendHttpStatus
* @param int $code
* @return void
*/
Expand Down
1 change: 0 additions & 1 deletion score/Core/BaseServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ public static function isEnablePvCollector() {
$isEnablePvCollector = false;
}
return $isEnablePvCollector;

}

/**
Expand Down
11 changes: 7 additions & 4 deletions score/Core/ComponentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ trait ComponentTrait {
* @param string $com_alias_name 组件别名
* @param array $defination 组件定义类
* @throws
* @return array
* @return mixed
*/

public function creatObject(string $com_alias_name = null, array $defination = []) {
Expand Down Expand Up @@ -64,16 +64,19 @@ public function creatObject(string $com_alias_name = null, array $defination = [
// 配置文件初始化创建公用对象
$coreComponents = $this->coreComponents();
$components = array_merge($coreComponents, Swfy::getAppConf()['components']);

foreach($components as $com_name=>$component) {

if($this->isSetOpenPoolsOfComponent($component)) {
$this->setOpenPoolsOfComponent($com_name);
continue;
}

// 存在直接跳过
if(isset($this->container[$com_name]) || (isset($component[SWOOLEFY_COM_IS_DELAY]) && $component[SWOOLEFY_COM_IS_DELAY])) {
continue;
if(isset($this->container[$com_name]) || isset($component[SWOOLEFY_COM_IS_DELAY])) {
$is_delay = filter_var($component[SWOOLEFY_COM_IS_DELAY], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if($is_delay === true) {
continue;
}
}

if(isset($component['class']) && $component['class'] != '') {
Expand Down
1 change: 1 addition & 0 deletions score/Core/HttpRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public function invoke($module = null, $controller = null, $action = null) {
// 方法调用发生异常后 引导到__call方法处理
$method = new \ReflectionMethod($controllerInstance, '__call');
$method->invokeArgs($controllerInstance, array($action, ''));

}catch(\Throwable $t) {
$query_string = isset($this->request->server['QUERY_STRING']) ? '?'.$this->request->server['QUERY_STRING'] : '';
$msg = 'Fatal error: '.$t->getMessage().' on '.$t->getFile().' on line '.$t->getLine(). ' ||| '.$this->request->server['REQUEST_URI'].$query_string;
Expand Down
3 changes: 0 additions & 3 deletions score/Core/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ public function returnJson($data, $formater = 'json') {
$string = $data;
default:$string = json_encode($data,0);break;
}
if($this->enable_gzip) {
$response->gzip($this->gzip_level);
}
$response->write($string);
}

Expand Down

0 comments on commit 4d28764

Please sign in to comment.