Skip to content

Commit a0802b3

Browse files
committed
Clean up
1 parent bcde6d9 commit a0802b3

File tree

3 files changed

+58
-59
lines changed

3 files changed

+58
-59
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ Curl::getInfo($opt = null)
208208
Curl::getOpt($option)
209209
Curl::getResponseCookie($key)
210210
Curl::head($url, $data = array())
211-
Curl::headerCallback($ch, $header)
212211
Curl::options($url, $data = array())
213212
Curl::patch($url, $data = array())
214213
Curl::post($url, $data = array(), $follow_303_with_post = false)

src/Curl/Curl.php

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -264,41 +264,6 @@ public function delete($url, $query_parameters = array(), $data = array())
264264
return $this->exec();
265265
}
266266

267-
/**
268-
* Download Complete
269-
*
270-
* @access private
271-
* @param $fh
272-
*/
273-
private function downloadComplete($fh)
274-
{
275-
if (!$this->error && $this->downloadCompleteFunction) {
276-
rewind($fh);
277-
$this->call($this->downloadCompleteFunction, $fh);
278-
$this->downloadCompleteFunction = null;
279-
}
280-
281-
if (is_resource($fh)) {
282-
fclose($fh);
283-
}
284-
285-
// Fix "PHP Notice: Use of undefined constant STDOUT" when reading the
286-
// PHP script from stdin. Using null causes "Warning: curl_setopt():
287-
// supplied argument is not a valid File-Handle resource".
288-
if (!defined('STDOUT')) {
289-
define('STDOUT', fopen('php://stdout', 'w'));
290-
}
291-
292-
// Reset CURLOPT_FILE with STDOUT to avoid: "curl_exec(): CURLOPT_FILE
293-
// resource has gone away, resetting to default".
294-
$this->setOpt(CURLOPT_FILE, STDOUT);
295-
296-
// Reset CURLOPT_RETURNTRANSFER to tell cURL to return subsequent
297-
// responses as the return value of curl_exec(). Without this,
298-
// curl_exec() will revert to returning boolean values.
299-
$this->setOpt(CURLOPT_RETURNTRANSFER, true);
300-
}
301-
302267
/**
303268
* Download
304269
*
@@ -503,25 +468,6 @@ public function head($url, $data = array())
503468
return $this->exec();
504469
}
505470

506-
/**
507-
* Create Header Callback
508-
*
509-
* @access private
510-
* @param $header_callback_data
511-
*
512-
* @return callable
513-
*/
514-
private function createHeaderCallback($header_callback_data)
515-
{
516-
return function ($ch, $header) use ($header_callback_data) {
517-
if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) === 1) {
518-
$header_callback_data->responseCookies[$cookie[1]] = trim($cookie[2], " \n\r\t\0\x0B");
519-
}
520-
$header_callback_data->rawResponseHeaders .= $header;
521-
return strlen($header);
522-
};
523-
}
524-
525471
/**
526472
* Options
527473
*
@@ -1080,7 +1026,7 @@ public function setTimeout($seconds)
10801026
public function setUrl($url, $mixed_data = '')
10811027
{
10821028
$this->baseUrl = $url;
1083-
$this->url = $this->buildURL($url, $mixed_data);
1029+
$this->url = $this->buildUrl($url, $mixed_data);
10841030
$this->setOpt(CURLOPT_URL, $this->url);
10851031
}
10861032

@@ -1238,7 +1184,7 @@ private function buildCookies()
12381184
*
12391185
* @return string
12401186
*/
1241-
private function buildURL($url, $mixed_data = '')
1187+
private function buildUrl($url, $mixed_data = '')
12421188
{
12431189
$query_string = '';
12441190
if (!empty($mixed_data)) {
@@ -1251,6 +1197,60 @@ private function buildURL($url, $mixed_data = '')
12511197
return $url . $query_string;
12521198
}
12531199

1200+
/**
1201+
* Create Header Callback
1202+
*
1203+
* @access private
1204+
* @param $header_callback_data
1205+
*
1206+
* @return callable
1207+
*/
1208+
private function createHeaderCallback($header_callback_data)
1209+
{
1210+
return function ($ch, $header) use ($header_callback_data) {
1211+
if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) === 1) {
1212+
$header_callback_data->responseCookies[$cookie[1]] = trim($cookie[2], " \n\r\t\0\x0B");
1213+
}
1214+
$header_callback_data->rawResponseHeaders .= $header;
1215+
return strlen($header);
1216+
};
1217+
}
1218+
1219+
/**
1220+
* Download Complete
1221+
*
1222+
* @access private
1223+
* @param $fh
1224+
*/
1225+
private function downloadComplete($fh)
1226+
{
1227+
if (!$this->error && $this->downloadCompleteFunction) {
1228+
rewind($fh);
1229+
$this->call($this->downloadCompleteFunction, $fh);
1230+
$this->downloadCompleteFunction = null;
1231+
}
1232+
1233+
if (is_resource($fh)) {
1234+
fclose($fh);
1235+
}
1236+
1237+
// Fix "PHP Notice: Use of undefined constant STDOUT" when reading the
1238+
// PHP script from stdin. Using null causes "Warning: curl_setopt():
1239+
// supplied argument is not a valid File-Handle resource".
1240+
if (!defined('STDOUT')) {
1241+
define('STDOUT', fopen('php://stdout', 'w'));
1242+
}
1243+
1244+
// Reset CURLOPT_FILE with STDOUT to avoid: "curl_exec(): CURLOPT_FILE
1245+
// resource has gone away, resetting to default".
1246+
$this->setOpt(CURLOPT_FILE, STDOUT);
1247+
1248+
// Reset CURLOPT_RETURNTRANSFER to tell cURL to return subsequent
1249+
// responses as the return value of curl_exec(). Without this,
1250+
// curl_exec() will revert to returning boolean values.
1251+
$this->setOpt(CURLOPT_RETURNTRANSFER, true);
1252+
}
1253+
12541254
/**
12551255
* Parse Headers
12561256
*

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,7 +3124,7 @@ public function testBuildUrlArgs()
31243124
foreach ($tests as $test) {
31253125
$curl_1 = new Curl();
31263126
$reflector = new \ReflectionObject($curl_1);
3127-
$method = $reflector->getMethod('buildURL');
3127+
$method = $reflector->getMethod('buildUrl');
31283128
$method->setAccessible(true);
31293129
$actual_url = $method->invoke($curl_1, $test['args']['url'], $test['args']['mixed_data']);
31303130
$this->assertEquals($test['expected'], $actual_url);
@@ -3152,7 +3152,7 @@ public function testBuildUrlArgSeparator()
31523152
$curl = new Curl();
31533153

31543154
$reflector = new \ReflectionObject($curl);
3155-
$method = $reflector->getMethod('buildURL');
3155+
$method = $reflector->getMethod('buildUrl');
31563156
$method->setAccessible(true);
31573157

31583158
$actual_url = $method->invoke($curl, $base_url, $data);

0 commit comments

Comments
 (0)