Merge pull request #348 from zachborboa/patch-1

Add output parameter to MultiCurl::verbose
This commit is contained in:
Zach Borboa
2016-07-04 11:50:57 -07:00
committed by GitHub
4 changed files with 35 additions and 11 deletions
+3 -3
View File
@@ -212,7 +212,7 @@ Curl::head($url, $data = array())
Curl::headerCallback($ch, $header)
Curl::options($url, $data = array())
Curl::patch($url, $data = array())
Curl::post($url, $data = array(), $post_redirect_get = false)
Curl::post($url, $data = array(), $follow_303_with_post = false)
Curl::progress($callback)
Curl::put($url, $data = array())
Curl::setBasicAuthentication($username, $password = '')
@@ -249,7 +249,7 @@ MultiCurl::addGet($url, $data = array())
MultiCurl::addHead($url, $data = array())
MultiCurl::addOptions($url, $data = array())
MultiCurl::addPatch($url, $data = array())
MultiCurl::addPost($url, $data = array(), $post_redirect_get = false)
MultiCurl::addPost($url, $data = array(), $follow_303_with_post = false)
MultiCurl::addPut($url, $data = array())
MultiCurl::beforeSend($callback)
MultiCurl::close()
@@ -273,7 +273,7 @@ MultiCurl::setXmlDecoder($function)
MultiCurl::start()
MultiCurl::success($callback)
MultiCurl::unsetHeader($key)
MultiCurl::verbose($on = true)
MultiCurl::verbose($on = true, $output=STDERR)
```
### Contribute
+2 -2
View File
@@ -929,8 +929,8 @@ class Curl
* Verbose
*
* @access public
* @param bool $on
* @param resource $output
* @param bool $on
* @param resource $output
*/
public function verbose($on = true, $output=STDERR)
{
+13 -6
View File
@@ -191,16 +191,16 @@ class MultiCurl
* @access public
* @param $url
* @param $data
* @param $post_redirect_get If true, will cause 303 redirections to be followed using
* @param $follow_303_with_post If true, will cause 303 redirections to be followed using
* GET requests (default: false).
* Note: Redirections are only followed if the CURLOPT_FOLLOWLOCATION option is set to true.
*
* @return object
*/
public function addPost($url, $data = array(), $post_redirect_get = false)
public function addPost($url, $data = array(), $follow_303_with_post = false)
{
if (is_array($url)) {
$post_redirect_get = (bool)$data;
$follow_303_with_post = (bool)$data;
$data = $url;
$url = $this->baseUrl;
}
@@ -217,7 +217,7 @@ class MultiCurl
* For post-redirect-get requests, the CURLOPT_CUSTOMREQUEST option must not
* be set, otherwise cURL will perform POST requests for redirections.
*/
if (!$post_redirect_get) {
if (!$follow_303_with_post) {
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'POST');
}
@@ -552,11 +552,18 @@ class MultiCurl
* Verbose
*
* @access public
* @param $on
* @param bool $on
* @param resource $output
*/
public function verbose($on = true)
public function verbose($on = true, $output=STDERR)
{
// Turn off CURLINFO_HEADER_OUT for verbose to work. This has the side
// effect of causing Curl::requestHeaders to be empty.
if ($on) {
$this->setOpt(CURLINFO_HEADER_OUT, false);
}
$this->setOpt(CURLOPT_VERBOSE, $on);
$this->setOpt(CURLOPT_STDERR, $output);
}
/**
@@ -2245,4 +2245,21 @@ class MultiCurlTest extends PHPUnit_Framework_TestCase
});
$multi_curl->start();
}
public function testAlternativeStandardErrorOutput()
{
$buffer = fopen('php://memory', 'w+');
$multi_curl = new MultiCurl();
$multi_curl->verbose(true, $buffer);
$multi_curl->addGet(Test::TEST_URL);
$multi_curl->start();
rewind($buffer);
$stderr = stream_get_contents($buffer);
fclose($buffer);
$this->assertNotEmpty($stderr);
}
}