Normalization of Context class

This commit is contained in:
whale
2020-04-15 10:55:10 +08:00
parent 676527205f
commit 1d2aaf3c99
8 changed files with 70 additions and 19 deletions

View File

@@ -18,8 +18,7 @@ class GlobalConfig
public $success = false;
public function __construct() {
/** @noinspection PhpIncludeInspection */
include_once WORKING_DIR.'/config/global.php';
include_once WORKING_DIR . '/config/global.php';
global $config;
$this->success = true;
$this->config = $config;
@@ -30,4 +29,8 @@ class GlobalConfig
if ($r === null) return null;
return $r;
}
}
public function getAll() {
return $this->config;
}
}

View File

@@ -2,7 +2,7 @@
use Framework\Console;
use Framework\ZMBuf;
use ZM\Utils\Context;
use ZM\Context\ContextInterface;
function classLoader($p) {
$filepath = getClassPath($p);
@@ -158,13 +158,17 @@ function set_coroutine_params($array) {
}
}
/**
* @return ContextInterface|null
*/
function context() {
$cid = Co::getCid();
$c_class = ZMBuf::globals("context_class");
if (isset(ZMBuf::$context[$cid])) {
return new Context(ZMBuf::$context[$cid], $cid);
return new $c_class(ZMBuf::$context[$cid], $cid);
} else {
while (($pcid = Co::getPcid($cid)) !== -1) {
if (isset(ZMBuf::$context[$cid])) return new Context(ZMBuf::$context[$cid], $cid);
if (isset(ZMBuf::$context[$cid])) return new $c_class(ZMBuf::$context[$cid], $cid);
else $cid = $pcid;
}
return null;