From f01d8030b202d55ebbc50e297110f5ab314e0385 Mon Sep 17 00:00:00 2001 From: v_haodouliu Date: Thu, 30 Apr 2020 17:51:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=90=86=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Gateways/Gateway.php | 25 +++++++++++++++++++++++++ src/Traits/HasHttpRequest.php | 8 ++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Gateways/Gateway.php b/src/Gateways/Gateway.php index a4b1310..c6791fc 100644 --- a/src/Gateways/Gateway.php +++ b/src/Gateways/Gateway.php @@ -26,6 +26,11 @@ abstract class Gateway implements GatewayInterface */ protected $config; + /** + * @var array + */ + protected $options; + /** * @var float */ @@ -85,6 +90,26 @@ public function setConfig(Config $config) return $this; } + /** + * @param $options + * + * @return $this + */ + public function setGuzzleOptions($options) + { + $this->options = $options; + + return $this; + } + + /** + * @return array + */ + public function getGuzzleOptions() + { + return $this->options ?: $this->config->get('options', []); + } + /** * {@inheritdoc} */ diff --git a/src/Traits/HasHttpRequest.php b/src/Traits/HasHttpRequest.php index 45217bd..969f49d 100644 --- a/src/Traits/HasHttpRequest.php +++ b/src/Traits/HasHttpRequest.php @@ -91,12 +91,12 @@ protected function request($method, $endpoint, $options = []) */ protected function getBaseOptions() { - $options = [ + $options = method_exists($this, 'getGuzzleOptions') ? $this->getGuzzleOptions() : []; + + return \array_merge($options, [ 'base_uri' => method_exists($this, 'getBaseUri') ? $this->getBaseUri() : '', 'timeout' => method_exists($this, 'getTimeout') ? $this->getTimeout() : 5.0, - ]; - - return $options; + ]); } /**