From f2dc33fca403aded0f5d9e3703490301c78b133b Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Thu, 19 Sep 2019 19:04:43 +0800 Subject: [PATCH] add clear --- wx/Miniprogarampage.php | 6 ++---- wx/Wx.php | 11 +++++++++++ wx/WxClient.php | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/wx/Miniprogarampage.php b/wx/Miniprogarampage.php index e6e3d0d..03fb3d2 100644 --- a/wx/Miniprogarampage.php +++ b/wx/Miniprogarampage.php @@ -25,11 +25,8 @@ abstract class Miniprogarampage */ private function __construct() { - if (!($this->request instanceof WxClient)) { - $this->request = new WxClient(); - } + $this->request = WxClient::getInstance(); $this->request->setIsSSL(true); - $this->request->setAgent($this->config->getAgent()); } /** @@ -42,6 +39,7 @@ abstract class Miniprogarampage static::$instance = new static(); } static::$instance->config = $config; + static::$instance->request->setAgent($config->getAgent()); return static::$instance; } diff --git a/wx/Wx.php b/wx/Wx.php index 2166e4d..02d3dfd 100644 --- a/wx/Wx.php +++ b/wx/Wx.php @@ -91,4 +91,15 @@ class Wx { return Notify::getInstance($this->config); } + + /** + * @return WxClient + */ + public function getClient() + { + $client = WxClient::getInstance(); + $client->setAgent($this->config->getAgent()); + return $client; + } + } diff --git a/wx/WxClient.php b/wx/WxClient.php index 427c124..b820326 100644 --- a/wx/WxClient.php +++ b/wx/WxClient.php @@ -23,6 +23,23 @@ class WxClient const DELETE = 'delete'; const OPTIONS = 'option'; + private static $_instance; + + private function __construct() + { + } + + /** + * @return WxClient + */ + public static function getInstance() + { + if (!(static::$_instance instanceof WxClient)) { + static::$_instance = new WxClient(); + } + return static::$_instance; + } + /** * @param string $host */