diff --git a/README.md b/README.md index a88ab91..f5020aa 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,6 @@ Curl::getInfo($opt = null) Curl::getOpt($option) Curl::getResponseCookie($key) Curl::head($url, $data = array()) -Curl::headerCallback($ch, $header) Curl::options($url, $data = array()) Curl::patch($url, $data = array()) Curl::post($url, $data = array(), $follow_303_with_post = false) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 11c4d35..c11cc37 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -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 * diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 10a24d3..f4f4c4a 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -3124,7 +3124,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase foreach ($tests as $test) { $curl_1 = new Curl(); $reflector = new \ReflectionObject($curl_1); - $method = $reflector->getMethod('buildURL'); + $method = $reflector->getMethod('buildUrl'); $method->setAccessible(true); $actual_url = $method->invoke($curl_1, $test['args']['url'], $test['args']['mixed_data']); $this->assertEquals($test['expected'], $actual_url); @@ -3152,7 +3152,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase $curl = new Curl(); $reflector = new \ReflectionObject($curl); - $method = $reflector->getMethod('buildURL'); + $method = $reflector->getMethod('buildUrl'); $method->setAccessible(true); $actual_url = $method->invoke($curl, $base_url, $data);