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 */