From e247fa44433a48c6d5395146a4ec21cb046e5242 Mon Sep 17 00:00:00 2001 From: Asan Osmanov Date: Tue, 28 May 2024 14:30:45 +0300 Subject: [PATCH] add GuzzleHttp config to client configuration --- src/AbstractController.php | 10 +++++++--- src/Media.php | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/AbstractController.php b/src/AbstractController.php index e819024..345258b 100644 --- a/src/AbstractController.php +++ b/src/AbstractController.php @@ -62,6 +62,9 @@ abstract class AbstractController /** @var array $post_body */ protected array $post_body = []; + /** @var array $guzzle_config */ + protected array $guzzle_config = []; + /** * Creates object. Requires an array of settings. * @param array $settings @@ -90,7 +93,7 @@ public function performRequest(array $postData = [], $withHeaders = false) if ($this->auth_mode === 0) { // Bearer Token // Inject the Bearer token header - $client = new Client(['base_uri' => self::API_BASE_URI]); + $client = new Client(array_merge($this->guzzle_config, ['base_uri' => self::API_BASE_URI])); $headers['Authorization'] = 'Bearer ' . $this->bearer_token; } elseif ($this->auth_mode === 1) { // OAuth 1.0a User Context // Insert Oauth1 middleware @@ -102,11 +105,11 @@ public function performRequest(array $postData = [], $withHeaders = false) 'token_secret' => $this->access_token_secret, ]); $stack->push($middleware); - $client = new Client([ + $client = new Client(array_merge($this->guzzle_config, [ 'base_uri' => self::API_BASE_URI, 'handler' => $stack, 'auth' => 'oauth' - ]); + ])); } else { // OAuth 2.0 Authorization Code Flow throw new \RuntimeException('OAuth 2.0 Authorization Code Flow had not been implemented & also requires user interaction.'); } @@ -205,6 +208,7 @@ private function parseSettings(array $settings): void $this->access_token = $settings['access_token']; $this->access_token_secret = $settings['access_token_secret']; $this->free_mode = $settings['free_mode'] ?? false; + $this->guzzle_config = $settings['guzzle_config'] ?? []; } /** diff --git a/src/Media.php b/src/Media.php index 0a3229a..a77da03 100644 --- a/src/Media.php +++ b/src/Media.php @@ -48,11 +48,11 @@ private function prepareRequest(array $settings = []): void 'token_secret' => $settings['access_token_secret'], ]); $stack->push($oAuth1); - $this->client = new Client([ + $this->client = new Client(array_merge($this->guzzle_config, [ 'base_uri' => "https://upload.twitter.com/1.1/", 'handler' => $stack, 'auth' => 'oauth' - ]); + ])); } /**