Skip to content

Commit

Permalink
[10.x] Global default options for the http factory (#49767)
Browse files Browse the repository at this point in the history
* Global default options for the http factory

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
timacdonald and taylorotwell authored Jan 21, 2024
1 parent ac7bbd3 commit 7f6bd6b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Client/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class Factory
*/
protected $globalMiddleware = [];

/**
* The options to apply to every request.
*
* @var array
*/
protected $globalOptions = [];

/**
* The stub callables that will handle requests.
*
Expand Down Expand Up @@ -123,6 +130,19 @@ public function globalResponseMiddleware($middleware)
return $this;
}

/**
* Set the options to apply to every request.
*
* @param array $options
* @return $this
*/
public function globalOptions($options)
{
$this->globalOptions = $options;

return $this;
}

/**
* Create a new response instance for use during stubbing.
*
Expand Down Expand Up @@ -400,7 +420,7 @@ public function recorded($callback = null)
*/
protected function newPendingRequest()
{
return new PendingRequest($this, $this->globalMiddleware);
return (new PendingRequest($this, $this->globalMiddleware))->withOptions($this->globalOptions);
}

/**
Expand Down

0 comments on commit 7f6bd6b

Please sign in to comment.