diff --git a/src/kaleido/http/Capture.php b/src/kaleido/http/Capture.php index 2453683..4e161b5 100755 --- a/src/kaleido/http/Capture.php +++ b/src/kaleido/http/Capture.php @@ -8,7 +8,6 @@ class Capture extends Worker { - public static $lock = []; public $activity = ['history', 'current']; public $leancloud = []; public $apiServer; @@ -94,13 +93,8 @@ private function activity($activity = null) { $this->switchHandle('request'); $this->setTiming(); new Sender(parent::getItem('request')); - $this->lockClass(); + parent::lockItem(); new Decoder(Sender::response(false)); } } - - private function lockClass() { - self::$lock = self::$item; - parent::resetClass(); - } } \ No newline at end of file diff --git a/src/kaleido/http/Decoder.php b/src/kaleido/http/Decoder.php index eb09d9a..732979c 100644 --- a/src/kaleido/http/Decoder.php +++ b/src/kaleido/http/Decoder.php @@ -5,7 +5,6 @@ class Decoder extends Worker { private static $handleItem = []; - private static $lock; public $error = false; public $errorCode = 0; public $respType; @@ -23,7 +22,7 @@ public function __construct(array $response) { parent::unpackItem($response); parent::matchTaskId(); $this->handle(); - $this->lockClass(); + parent::lockItem(__CLASS__); } private function handle() { @@ -42,11 +41,6 @@ private function checkError() { } } - private function lockClass() { - self::$lock = self::$item; - self::resetClass(); - } - public static function getHandle($item = null) { return self::$handleItem[$item] ?? null; } @@ -57,14 +51,14 @@ private function setHandle() { } public static function class($encode) { - return $encode ? json_encode(self::$lock) - : (array)self::$lock; + return $encode ? json_encode(parent::$lock[__CLASS__]) + : (array)parent::$lock[__CLASS__]; } public static function getBody() { - \is_string(self::$lock['body']) ?: new HttpException( - parent::getError('0x02'), 500); - return self::$lock['body']; + \is_string(parent::$lock[__CLASS__]['body']) + ?: new HttpException(parent::getError('0x02'), 500); + return parent::$lock[__CLASS__]['body']; } private function setResponseDate() { diff --git a/src/kaleido/http/Encoder.php b/src/kaleido/http/Encoder.php index 03921d0..a972edb 100644 --- a/src/kaleido/http/Encoder.php +++ b/src/kaleido/http/Encoder.php @@ -7,7 +7,6 @@ class Encoder extends Worker public $allow = ['post', 'put', 'head', 'options', 'search', 'patch', 'delete']; public $method; public $host; - private static $lock = []; /** * Encoder constructor. @@ -21,7 +20,7 @@ public function __construct($taskId, $url) { parent::matchTaskId($taskId); $this->check($url); $this->handle($taskId, $url); - $this->lockClass(); + parent::lockItem(__CLASS__); } private function check($url) { @@ -35,14 +34,9 @@ private function handle($taskId, $url) { ->setCookie()->setHeader()->setMaxSize(); } - private function lockClass() { - self::$lock = self::$item; - self::resetClass(); - } - - public static function class($encode) { - return $encode ? json_encode(self::$lock) - : self::$lock; + public static function payload($encode) { + return $encode ? json_encode(parent::$lock[__CLASS__]) + : (array)parent::$lock[__CLASS__]; } private function getHost($url = null) :string { diff --git a/src/kaleido/http/LeanCloud.php b/src/kaleido/http/LeanCloud.php index 1358dd1..3a0717e 100755 --- a/src/kaleido/http/LeanCloud.php +++ b/src/kaleido/http/LeanCloud.php @@ -41,7 +41,7 @@ public static function setApiServer($apiServer) { } public function setRequest(LeanObject $class) :LeanObject { - return $class->set('request', Encoder::class(false)); + return $class->set('request', Encoder::payload(false)); } public function setResponse(LeanObject $class) :LeanObject { diff --git a/src/kaleido/http/Loader.php b/src/kaleido/http/Loader.php index ba77afc..f51974f 100644 --- a/src/kaleido/http/Loader.php +++ b/src/kaleido/http/Loader.php @@ -7,7 +7,6 @@ class Loader extends Worker { - public static $lock = []; public $allow = ['dynamic']; public $expire = []; public $hashName; @@ -25,7 +24,7 @@ public function __construct() { $this->getEnv('database'); $this->unpackItem('loadInfo'); $this->handle(); - $this->lockClass(); + parent::lockItem(__CLASS__); } public function __toString() { @@ -95,8 +94,8 @@ private function loadDatabase() { } public static function fetch() { - return \is_string(self::$lock['fetch']) - ? self::$lock['fetch'] : 'error_fetch'; + return \is_string(self::$lock[__CLASS__]['fetch']) + ? self::$lock[__CLASS__]['fetch'] : 'error_fetch'; } private function local($setName, $fileName) { @@ -134,7 +133,7 @@ private function setLoadCache($name, $value = null) { */ public function listenHttp($taskId, $url) :string { new Encoder($taskId, $url); - new Sender(Encoder::class(false)); + new Sender(Encoder::payload(false)); new Decoder(Sender::response(false)); new Capture(); return Decoder::getBody(); @@ -165,11 +164,6 @@ private function setConsole() { : error_log('redisExpire: '. (parent::getItem('expire') - time())); } - private function lockClass() { - self::$lock = self::$item; - self::resetClass(); - } - private function isJson($data = null) { if (!\is_object(json_decode($data))) { new HttpException( diff --git a/src/kaleido/http/Sender.php b/src/kaleido/http/Sender.php index 0ad303b..4fa64b1 100644 --- a/src/kaleido/http/Sender.php +++ b/src/kaleido/http/Sender.php @@ -7,7 +7,6 @@ class Sender extends Worker { - private static $lock; public $protocol = ['get', 'post', 'put', 'head', 'options', 'search', 'patch', 'delete']; public $maxSize; public $url; @@ -25,7 +24,7 @@ public function __construct(array $payload) { parent::unpackItem($payload); $this->check(); $this->handle(); - $this->lockClass(); + parent::lockItem(__CLASS__); } public function check() { @@ -52,14 +51,9 @@ public function handle() { : $this->setBody($curl->response, $curl->responseHeaders); } - private function lockClass() { - self::$lock = self::$item; - self::resetClass(); - } - public static function response($encode) { - return $encode ? json_encode(self::$lock) - : (array)self::$lock; + return $encode ? json_encode(self::$lock[__CLASS__]) + : (array)self::$lock[__CLASS__]; } private function setTaskId() { diff --git a/src/kaleido/http/Worker.php b/src/kaleido/http/Worker.php index edad58f..9bae8d6 100644 --- a/src/kaleido/http/Worker.php +++ b/src/kaleido/http/Worker.php @@ -4,6 +4,7 @@ class Worker { + protected static $lock = []; public static $loader; public static $timing = []; public static $item = []; @@ -124,7 +125,8 @@ protected static function getError($id = null) :string { }); } - protected static function resetClass() :array { + protected function lockItem($className = null) :array { + self::$lock[$className] = self::$item; return self::$item = []; } } \ No newline at end of file