From 6e6021f0882a1ca2ac1c7be55903ffbe469d5aad Mon Sep 17 00:00:00 2001 From: Lyuboslav Alexandrov Date: Mon, 26 Jun 2023 15:32:30 +0300 Subject: [PATCH 1/2] Added guzzle middleware configuration options and factory adjusting --- config/firebase.php | 4 ++++ src/FirebaseProjectManager.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/config/firebase.php b/config/firebase.php index 2bc4811..1b541a1 100644 --- a/config/firebase.php +++ b/config/firebase.php @@ -179,6 +179,10 @@ * https://github.com/kreait/firebase-php/blob/6.x/src/Firebase/Http/HttpClientOptions.php */ 'timeout' => env('FIREBASE_HTTP_CLIENT_TIMEOUT'), + + 'guzzle_middlewares' => [ + + ] ], ], ], diff --git a/src/FirebaseProjectManager.php b/src/FirebaseProjectManager.php index 3b24aa4..12221d5 100644 --- a/src/FirebaseProjectManager.php +++ b/src/FirebaseProjectManager.php @@ -123,6 +123,10 @@ protected function configure(string $name): FirebaseProject $options = $options->withTimeOut((float) $timeout); } + if ($middlewares = $config['http_client_options']['guzzle_middlewares'] ?? null) { + $options = $options->withGuzzleMiddlewares($middlewares); + } + $factory = $factory->withHttpClientOptions($options); return new FirebaseProject($factory, $config); From 5d680bf65e49e19cda766a38919469fc11e8654e Mon Sep 17 00:00:00 2001 From: Lyuboslav Alexandrov Date: Mon, 26 Jun 2023 15:32:49 +0300 Subject: [PATCH 2/2] Added a test --- tests/FirebaseProjectManagerTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/FirebaseProjectManagerTest.php b/tests/FirebaseProjectManagerTest.php index cc3b6bb..adfd87f 100644 --- a/tests/FirebaseProjectManagerTest.php +++ b/tests/FirebaseProjectManagerTest.php @@ -4,6 +4,7 @@ namespace Kreait\Laravel\Firebase\Tests; +use GuzzleHttp\RetryMiddleware; use Kreait\Firebase; use Kreait\Firebase\Exception\InvalidArgumentException; use Kreait\Firebase\Factory; @@ -201,6 +202,7 @@ public function http_client_options_can_be_configured(): void $projectName = $this->app->config->get('firebase.default'); $this->app->config->set('firebase.projects.' . $projectName . '.http_client_options.proxy', 'proxy.domain.tld'); $this->app->config->set('firebase.projects.' . $projectName . '.http_client_options.timeout', 1.23); + $this->app->config->set('firebase.projects.' . $projectName . '.http_client_options.guzzle_middlewares', [RetryMiddleware::class]); $factory = $this->factoryForProject($projectName); @@ -209,6 +211,7 @@ public function http_client_options_can_be_configured(): void $this->assertSame('proxy.domain.tld', $httpClientOptions->proxy()); $this->assertSame(1.23, $httpClientOptions->timeout()); + $this->assertSame([RetryMiddleware::class], $httpClientOptions->guzzleMiddlewares()); } /**