Skip to content

Commit be6f9f5

Browse files
Nyholmdbu
authored andcommitted
Allow CURL constant names (#82)
Allow CURL constant names and validate we found them
1 parent f56531b commit be6f9f5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ClientFactory/CurlFactory.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ public function createClient(array $config = [])
4040
throw new \LogicException('To use the Curl client you need to install the "php-http/curl-client" package.');
4141
}
4242

43+
// Try to resolve curl constant names
44+
foreach ($config as $key => $value) {
45+
// If the $key is a string we assume it is a constant
46+
if (is_string($key)) {
47+
if (null === ($constantValue = constant($key))) {
48+
throw new \LogicException(sprintf('Key %s is not an int nor a CURL constant', $key));
49+
}
50+
51+
unset($config[$key]);
52+
$config[$constantValue] = $value;
53+
}
54+
}
55+
4356
return new Client($this->messageFactory, $this->streamFactory, $config);
4457
}
4558
}

0 commit comments

Comments
 (0)