Skip to content

Commit cf107b8

Browse files
authored
Merge pull request php-curl-class#408 from zachborboa/master
Allow calling Curl::getInfo() without option
2 parents 9ad5458 + 9bfdd79 commit cf107b8

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Curl::error($callback)
201201
Curl::exec($ch = null)
202202
Curl::get($url, $data = array())
203203
Curl::getCookie($key)
204-
Curl::getInfo($opt)
204+
Curl::getInfo($opt = null)
205205
Curl::getOpt($option)
206206
Curl::getResponseCookie($key)
207207
Curl::head($url, $data = array())

src/Curl/Curl.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,16 @@ public function get($url, $data = array())
422422
*
423423
* @return mixed
424424
*/
425-
public function getInfo($opt)
425+
public function getInfo($opt = null)
426426
{
427-
return curl_getinfo($this->curl, $opt);
427+
$args = array();
428+
$args[] = $this->curl;
429+
430+
if (func_num_args()) {
431+
$args[] = $opt;
432+
}
433+
434+
return call_user_func_array('curl_getinfo', $args);
428435
}
429436

430437
/**

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,4 +3000,61 @@ public function testUnsetHeader()
30003000
$curl->get(Test::TEST_URL, $data);
30013001
$this->assertEquals('', $curl->response);
30023002
}
3003+
3004+
public function testGetInfo()
3005+
{
3006+
$test = new Test();
3007+
$test->server('server', 'GET');
3008+
$info = $test->curl->getInfo();
3009+
3010+
$expected_keys = array(
3011+
'url',
3012+
'content_type',
3013+
'http_code',
3014+
'header_size',
3015+
'request_size',
3016+
'filetime',
3017+
'ssl_verify_result',
3018+
'redirect_count',
3019+
'total_time',
3020+
'namelookup_time',
3021+
'connect_time',
3022+
'pretransfer_time',
3023+
'size_upload',
3024+
'size_download',
3025+
'speed_download',
3026+
'speed_upload',
3027+
'download_content_length',
3028+
'upload_content_length',
3029+
'starttransfer_time',
3030+
'redirect_time',
3031+
'certinfo',
3032+
'primary_ip',
3033+
'primary_port',
3034+
'local_ip',
3035+
'local_port',
3036+
'redirect_url',
3037+
'request_header',
3038+
);
3039+
3040+
// Not all keys are included on PHP 5.3 (tested 5.3.29).
3041+
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
3042+
foreach (array('primary_ip', 'primary_port', 'local_ip', 'local_port') as $value) {
3043+
$key = array_search($value, $expected_keys);
3044+
unset($expected_keys[$key]);
3045+
}
3046+
}
3047+
3048+
// Not all keys are included on HHVM (tested 3.6.6).
3049+
if (defined('HHVM_VERSION')) {
3050+
foreach (array('certinfo', 'primary_ip', 'primary_port', 'local_ip', 'redirect_url') as $value) {
3051+
$key = array_search($value, $expected_keys);
3052+
unset($expected_keys[$key]);
3053+
}
3054+
}
3055+
3056+
foreach ($expected_keys as $key) {
3057+
$this->assertArrayHasKey($key, $info);
3058+
}
3059+
}
30033060
}

0 commit comments

Comments
 (0)