Skip to content

Commit 44f09fd

Browse files
committed
Merge pull request php-curl-class#297 from zachborboa/master
Add MultiCurl::setXmlDecoder
2 parents dce9acb + ebca4c2 commit 44f09fd

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ MultiCurl::setReferrer($referrer)
248248
MultiCurl::setTimeout($seconds)
249249
MultiCurl::setURL($url)
250250
MultiCurl::setUserAgent($user_agent)
251+
MultiCurl::setXmlDecoder($function)
251252
MultiCurl::start()
252253
MultiCurl::success($callback)
253254
MultiCurl::unsetHeader($key)

src/Curl/MultiCurl.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class MultiCurl
2121
private $options = array();
2222

2323
private $jsonDecoder = null;
24+
private $xmlDecoder = null;
2425

2526
/**
2627
* Construct
@@ -387,6 +388,19 @@ public function setJsonDecoder($function)
387388
}
388389
}
389390

391+
/**
392+
* Set XML Decoder
393+
*
394+
* @access public
395+
* @param $function
396+
*/
397+
public function setXmlDecoder($function)
398+
{
399+
if (is_callable($function)) {
400+
$this->xmlDecoder = $function;
401+
}
402+
}
403+
390404
/**
391405
* Set Opt
392406
*
@@ -593,6 +607,7 @@ private function initHandle($curl)
593607
$curl->setHeader($key, $value);
594608
}
595609
$curl->setJsonDecoder($this->jsonDecoder);
610+
$curl->setXmlDecoder($this->xmlDecoder);
596611
$curl->call($curl->beforeSendFunction);
597612
}
598613
}

tests/PHPCurlClass/PHPMultiCurlClassTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,36 @@ public function testJSONDecoder()
19611961
$this->assertEquals('bar', $get_2->response);
19621962
}
19631963

1964+
public function testXMLDecoder()
1965+
{
1966+
$multi_curl = new MultiCurl();
1967+
$multi_curl->setHeader('X-DEBUG-TEST', 'xml_with_cdata_response');
1968+
$multi_curl->setXmlDecoder(function($response) {
1969+
return 'foo';
1970+
});
1971+
1972+
$get_1 = $multi_curl->addGet(Test::TEST_URL);
1973+
$get_1->complete(function ($instance) {
1974+
PHPUnit_Framework_Assert::assertInstanceOf('Curl\Curl', $instance);
1975+
PHPUnit_Framework_Assert::assertEquals('foo', $instance->response);
1976+
});
1977+
1978+
$get_2 = $multi_curl->addGet(Test::TEST_URL);
1979+
$get_2->beforeSend(function ($instance) {
1980+
$instance->setXmlDecoder(function($response) {
1981+
return 'bar';
1982+
});
1983+
});
1984+
$get_2->complete(function ($instance) {
1985+
PHPUnit_Framework_Assert::assertInstanceOf('Curl\Curl', $instance);
1986+
PHPUnit_Framework_Assert::assertEquals('bar', $instance->response);
1987+
});
1988+
1989+
$multi_curl->start();
1990+
$this->assertEquals('foo', $get_1->response);
1991+
$this->assertEquals('bar', $get_2->response);
1992+
}
1993+
19641994
public function testDownloadCallback()
19651995
{
19661996
// Upload a file.

0 commit comments

Comments
 (0)