Skip to content

Allow CURL constant names #82

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

Merged
merged 2 commits into from
Jun 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ClientFactory/CurlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ public function createClient(array $config = [])
throw new \LogicException('To use the Curl client you need to install the "php-http/curl-client" package.');
}

// Try to resolve curl constant names
foreach ($config as $key => $value) {
// If the $key is a string we assume it is a constant
if (is_string($key)) {
if (null === ($constantValue = constant($key))) {
throw new \LogicException(sprintf('Key %s is not an int nor a CURL constant', $key));
}

unset($config[$key]);
$config[$constantValue] = $value;
}
}

return new Client($this->messageFactory, $this->streamFactory, $config);
}
}