8000 Dynamically populate the proxy types list · adamwiw/codebird-php@300973d · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 300973d

Browse files
committed
Dynamically populate the proxy types list
This also fixes the HHVM build.
1 parent 3a75095 commit 300973d

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/codebird.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -721,16 +721,14 @@ public function setReturnFormat($return_format)
721721
*/
722722
public function setProxy($host, $port, $type = CURLPROXY_HTTP)
723723
{
724-
$types = [
725-
CURLPROXY_HTTP, CURLPROXY_SOCKS4, CURLPROXY_SOCKS5
724+
static $types_str = [
725+
'HTTP', 'SOCKS4', 'SOCKS5', 'SOCKS4A', 'SOCKS5_HOSTNAME'
726726
];
727-
// PHP 7.0+, keep this as long as PHP 5.6 is supported
728-
if (defined('CURLPROXY_SOCKS4A')) {
729-
$types[] = CURLPROXY_SOCKS4A;
730-
}
731-
// PHP 7.0+, keep this as long as PHP 5.6 is supported
732-
if (defined('CURLPROXY_SOCKS5_HOSTNAME')) {
733-
$types[] = CURLPROXY_SOCKS5_HOSTNAME;
727+
$types = [];
728+
foreach ($types_str as $type_str) {
729+
if (defined('CURLPROXY_' . $type_str)) {
730+
$types[] = constant('CURLPROXY_' . $type_str);
731+
}
734732
}
735733
if (! in_array($type, $types)) {
736734
throw new \Exception('Invalid proxy type specified.');

0 commit comments

Comments
 (0)
0