mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-10-08 04:55:22 +00:00
Clean up
This commit is contained in:
+56
-56
@@ -264,41 +264,6 @@ class Curl
|
||||
return $this->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Download Complete
|
||||
*
|
||||
* @access private
|
||||
* @param $fh
|
||||
*/
|
||||
private function downloadComplete($fh)
|
||||
{
|
||||
if (!$this->error && $this->downloadCompleteFunction) {
|
||||
rewind($fh);
|
||||
$this->call($this->downloadCompleteFunction, $fh);
|
||||
$this->downloadCompleteFunction = null;
|
||||
}
|
||||
|
||||
if (is_resource($fh)) {
|
||||
fclose($fh);
|
||||
}
|
||||
|
||||
// Fix "PHP Notice: Use of undefined constant STDOUT" when reading the
|
||||
// PHP script from stdin. Using null causes "Warning: curl_setopt():
|
||||
// supplied argument is not a valid File-Handle resource".
|
||||
if (!defined('STDOUT')) {
|
||||
define('STDOUT', fopen('php://stdout', 'w'));
|
||||
}
|
||||
|
||||
// Reset CURLOPT_FILE with STDOUT to avoid: "curl_exec(): CURLOPT_FILE
|
||||
// resource has gone away, resetting to default".
|
||||
$this->setOpt(CURLOPT_FILE, STDOUT);
|
||||
|
||||
// Reset CURLOPT_RETURNTRANSFER to tell cURL to return subsequent
|
||||
// responses as the return value of curl_exec(). Without this,
|
||||
// curl_exec() will revert to returning boolean values.
|
||||
$this->setOpt(CURLOPT_RETURNTRANSFER, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download
|
||||
*
|
||||
@@ -503,25 +468,6 @@ class Curl
|
||||
return $this->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Header Callback
|
||||
*
|
||||
* @access private
|
||||
* @param $header_callback_data
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
private function createHeaderCallback($header_callback_data)
|
||||
{
|
||||
return function ($ch, $header) use ($header_callback_data) {
|
||||
if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) === 1) {
|
||||
$header_callback_data->responseCookies[$cookie[1]] = trim($cookie[2], " \n\r\t\0\x0B");
|
||||
}
|
||||
$header_callback_data->rawResponseHeaders .= $header;
|
||||
return strlen($header);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Options
|
||||
*
|
||||
@@ -1080,7 +1026,7 @@ class Curl
|
||||
public function setUrl($url, $mixed_data = '')
|
||||
{
|
||||
$this->baseUrl = $url;
|
||||
$this->url = $this->buildURL($url, $mixed_data);
|
||||
$this->url = $this->buildUrl($url, $mixed_data);
|
||||
$this->setOpt(CURLOPT_URL, $this->url);
|
||||
}
|
||||
|
||||
@@ -1238,7 +1184,7 @@ class Curl
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function buildURL($url, $mixed_data = '')
|
||||
private function buildUrl($url, $mixed_data = '')
|
||||
{
|
||||
$query_string = '';
|
||||
if (!empty($mixed_data)) {
|
||||
@@ -1251,6 +1197,60 @@ class Curl
|
||||
return $url . $query_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Header Callback
|
||||
*
|
||||
* @access private
|
||||
* @param $header_callback_data
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
private function createHeaderCallback($header_callback_data)
|
||||
{
|
||||
return function ($ch, $header) use ($header_callback_data) {
|
||||
if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) === 1) {
|
||||
$header_callback_data->responseCookies[$cookie[1]] = trim($cookie[2], " \n\r\t\0\x0B");
|
||||
}
|
||||
$header_callback_data->rawResponseHeaders .= $header;
|
||||
return strlen($header);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Download Complete
|
||||
*
|
||||
* @access private
|
||||
* @param $fh
|
||||
*/
|
||||
private function downloadComplete($fh)
|
||||
{
|
||||
if (!$this->error && $this->downloadCompleteFunction) {
|
||||
rewind($fh);
|
||||
$this->call($this->downloadCompleteFunction, $fh);
|
||||
$this->downloadCompleteFunction = null;
|
||||
}
|
||||
|
||||
if (is_resource($fh)) {
|
||||
fclose($fh);
|
||||
}
|
||||
|
||||
// Fix "PHP Notice: Use of undefined constant STDOUT" when reading the
|
||||
// PHP script from stdin. Using null causes "Warning: curl_setopt():
|
||||
// supplied argument is not a valid File-Handle resource".
|
||||
if (!defined('STDOUT')) {
|
||||
define('STDOUT', fopen('php://stdout', 'w'));
|
||||
}
|
||||
|
||||
// Reset CURLOPT_FILE with STDOUT to avoid: "curl_exec(): CURLOPT_FILE
|
||||
// resource has gone away, resetting to default".
|
||||
$this->setOpt(CURLOPT_FILE, STDOUT);
|
||||
|
||||
// Reset CURLOPT_RETURNTRANSFER to tell cURL to return subsequent
|
||||
// responses as the return value of curl_exec(). Without this,
|
||||
// curl_exec() will revert to returning boolean values.
|
||||
$this->setOpt(CURLOPT_RETURNTRANSFER, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Headers
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user