mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-26 08:59:21 +00:00
Add MultiCurl::setXmlDecoder
This commit is contained in:
@@ -248,6 +248,7 @@ MultiCurl::setReferrer($referrer)
|
||||
MultiCurl::setTimeout($seconds)
|
||||
MultiCurl::setURL($url)
|
||||
MultiCurl::setUserAgent($user_agent)
|
||||
MultiCurl::setXmlDecoder($function)
|
||||
MultiCurl::start()
|
||||
MultiCurl::success($callback)
|
||||
MultiCurl::unsetHeader($key)
|
||||
|
||||
@@ -21,6 +21,7 @@ class MultiCurl
|
||||
private $options = array();
|
||||
|
||||
private $jsonDecoder = null;
|
||||
private $xmlDecoder = null;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
@@ -387,6 +388,19 @@ class MultiCurl
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set XML Decoder
|
||||
*
|
||||
* @access public
|
||||
* @param $function
|
||||
*/
|
||||
public function setXmlDecoder($function)
|
||||
{
|
||||
if (is_callable($function)) {
|
||||
$this->xmlDecoder = $function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Opt
|
||||
*
|
||||
@@ -593,6 +607,7 @@ class MultiCurl
|
||||
$curl->setHeader($key, $value);
|
||||
}
|
||||
$curl->setJsonDecoder($this->jsonDecoder);
|
||||
$curl->setXmlDecoder($this->xmlDecoder);
|
||||
$curl->call($curl->beforeSendFunction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1961,6 +1961,36 @@ class MultiCurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('bar', $get_2->response);
|
||||
}
|
||||
|
||||
public function testXMLDecoder()
|
||||
{
|
||||
$multi_curl = new MultiCurl();
|
||||
$multi_curl->setHeader('X-DEBUG-TEST', 'xml_with_cdata_response');
|
||||
$multi_curl->setXmlDecoder(function($response) {
|
||||
return 'foo';
|
||||
});
|
||||
|
||||
$get_1 = $multi_curl->addGet(Test::TEST_URL);
|
||||
$get_1->complete(function ($instance) {
|
||||
PHPUnit_Framework_Assert::assertInstanceOf('Curl\Curl', $instance);
|
||||
PHPUnit_Framework_Assert::assertEquals('foo', $instance->response);
|
||||
});
|
||||
|
||||
$get_2 = $multi_curl->addGet(Test::TEST_URL);
|
||||
$get_2->beforeSend(function ($instance) {
|
||||
$instance->setXmlDecoder(function($response) {
|
||||
return 'bar';
|
||||
});
|
||||
});
|
||||
$get_2->complete(function ($instance) {
|
||||
PHPUnit_Framework_Assert::assertInstanceOf('Curl\Curl', $instance);
|
||||
PHPUnit_Framework_Assert::assertEquals('bar', $instance->response);
|
||||
});
|
||||
|
||||
$multi_curl->start();
|
||||
$this->assertEquals('foo', $get_1->response);
|
||||
$this->assertEquals('bar', $get_2->response);
|
||||
}
|
||||
|
||||
public function testDownloadCallback()
|
||||
{
|
||||
// Upload a file.
|
||||
|
||||
Reference in New Issue
Block a user