From b1f3f0de77f6530206f598a2e90efbdd1c494de1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 8 Mar 2024 15:04:03 -0600 Subject: [PATCH] support closure based global options --- src/Illuminate/Http/Client/Factory.php | 6 +++--- tests/Http/HttpClientTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Http/Client/Factory.php b/src/Illuminate/Http/Client/Factory.php index 4bcd13d21b09..6ae3c54297bb 100644 --- a/src/Illuminate/Http/Client/Factory.php +++ b/src/Illuminate/Http/Client/Factory.php @@ -39,7 +39,7 @@ class Factory /** * The options to apply to every request. * - * @var array + * @var \Closure|array */ protected $globalOptions = []; @@ -133,7 +133,7 @@ public function globalResponseMiddleware($middleware) /** * Set the options to apply to every request. * - * @param array $options + * @param \Closure|array $options * @return $this */ public function globalOptions($options) @@ -420,7 +420,7 @@ public function recorded($callback = null) */ protected function newPendingRequest() { - return (new PendingRequest($this, $this->globalMiddleware))->withOptions($this->globalOptions); + return (new PendingRequest($this, $this->globalMiddleware))->withOptions(value($this->globalOptions)); } /** diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 52f57533f981..6590bf78f143 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -3011,7 +3011,7 @@ public function testItCanHaveGlobalDefaultValues() $this->assertFalse($allowRedirects); $this->assertSame(['true'], $headers['X-Foo']); - $factory->globalOptions([ + $factory->globalOptions(fn () => [ 'timeout' => 10, 'headers' => [ 'X-Foo' => 'false',