Skip to content

Commit

Permalink
Merge pull request #252 from finecho/master
Browse files Browse the repository at this point in the history
增加 Guzzle 选项配置
  • Loading branch information
overtrue authored Apr 30, 2020
2 parents dae4137 + f01d803 commit 91cbbd3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/Gateways/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ abstract class Gateway implements GatewayInterface
*/
protected $config;

/**
* @var array
*/
protected $options;

/**
* @var float
*/
Expand Down Expand Up @@ -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}
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Traits/HasHttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
]);
}

/**
Expand Down

0 comments on commit 91cbbd3

Please sign in to comment.