diff --git a/Api.php b/Api.php index 862b466..2fe65e1 100644 --- a/Api.php +++ b/Api.php @@ -32,14 +32,21 @@ class Api * @var ClientInterface */ private $client; - + + /** + * @var array + */ + private $config = []; + /** * @param AuthInterface $auth + * @param array $config additional config setting for client service */ - public function __construct(AuthInterface $auth) + public function __construct(AuthInterface $auth, $config = []) { $this->auth = $auth; $this->auth->setContext($this); + $this->config = $config; } /** @@ -280,7 +287,7 @@ public function request($method, $params = []) public function getClient() { if ($this->client === null) { - $this->client = new Client(); + $this->client = new Client($this->config); } return $this->client; diff --git a/Client/Client.php b/Client/Client.php index 72b9c21..7772d57 100644 --- a/Client/Client.php +++ b/Client/Client.php @@ -6,12 +6,26 @@ class Client implements ClientInterface { + /** + * Additional configuration for Guzzle Client. + * For example @link http://docs.guzzlephp.org/en/stable/request-options.html#verify + * @var array + */ + protected $config = []; /** * @var string */ private $baseUrl = 'https://sms.ru/{method}'; + /** + * @param array $config + */ + public function __construct($config = []) + { + $this->config = $config; + } + /** * @param string $method * @param array $params @@ -24,7 +38,10 @@ public function request($method, $params = []) { $client = new \GuzzleHttp\Client(); - $response = $client->post($this->getUrl($method), ['query' => $params]); + // Merge with specific config + $params = array_merge($this->config, ['query' => $params]); + + $response = $client->post($this->getUrl($method), $params); if ($response->getStatusCode() === 200) { return (string)$response->getBody(); diff --git a/Client/ClientInterface.php b/Client/ClientInterface.php index ede802f..1142da4 100644 --- a/Client/ClientInterface.php +++ b/Client/ClientInterface.php @@ -5,6 +5,12 @@ interface ClientInterface { + /** + * Provides an additional configs for client service + * @param array $config + */ + public function __construct($config = []); + /** * @param string $method * @param array $params