Skip to content

Commit

Permalink
Allow CURL constant names (php-http#82)
Browse files Browse the repository at this point in the history
Allow CURL constant names and validate we found them
  • Loading branch information
Nyholm authored and dbu committed Jun 30, 2016
1 parent f56531b commit be6f9f5
Showing 1 changed file with 13 additions and 0 deletions.
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);
}
}

0 comments on commit be6f9f5

Please sign in to comment.