New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Client::withConfig() #3078
Comments
Nice idea. A method that returns a new client, but retains the inner handler is what I had in mind here. That track with what you were thinking, too? |
Absolutely! |
@GrahamCampbell Would this just be same as the constructor but via a static call in https://github.com/guzzle/guzzle/blob/master/src/Client.php? public static function withConfig(array $config = [])
{
return new static($config);
} If yes, I'd be happy to work on this issue |
No. That does not retain the inner handler. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 2 weeks if no further activity occurs. Thank you for your contributions. |
Does this "retain the inner handler"? public function withConfig(array $config = []): self
{
$changedConfig = $config + $this->config;
// Retain inner handler?
$changedConfig["handler"] = $this->config["handler"];
return new self($changedConfig);
} public function testWithConfig()
{
$baseClient = new Client([
RequestOptions::TIMEOUT => 10,
RequestOptions::CONNECT_TIMEOUT => 20,
]);
$baseConfig = Helpers::readObjectAttribute($baseClient, 'config');
$mergedClient = $baseClient->withConfig([
RequestOptions::TIMEOUT => 50,
'handler' => function () {},
]);
$mergedConfig = Helpers::readObjectAttribute($mergedClient, 'config');
self::assertSame($mergedConfig[RequestOptions::TIMEOUT], 50);
self::assertSame($mergedConfig[RequestOptions::CONNECT_TIMEOUT], 20);
self::assertSame($baseConfig['handler'], $mergedConfig['handler']);
} |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 2 weeks if no further activity occurs. Thank you for your contributions. |
It'd be useful to add
Client::withConfig()
to allow derivating a custom-configured client from a preexisting one, eg to change the default timeout for a local need, etc.The text was updated successfully, but these errors were encountered: