File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -248,6 +248,7 @@ MultiCurl::setReferrer($referrer)
248
248
MultiCurl::setTimeout($seconds)
249
249
MultiCurl::setURL($url)
250
250
MultiCurl::setUserAgent($user_agent)
251
+ MultiCurl::setXmlDecoder($function)
251
252
MultiCurl::start()
252
253
MultiCurl::success($callback)
253
254
MultiCurl::unsetHeader($key)
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class MultiCurl
21
21
private $ options = array ();
22
22
23
23
private $ jsonDecoder = null ;
24
+ private $ xmlDecoder = null ;
24
25
25
26
/**
26
27
* Construct
@@ -387,6 +388,19 @@ public function setJsonDecoder($function)
387
388
}
388
389
}
389
390
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
+
390
404
/**
391
405
* Set Opt
392
406
*
@@ -593,6 +607,7 @@ private function initHandle($curl)
593
607
$ curl ->setHeader ($ key , $ value );
594
608
}
595
609
$ curl ->setJsonDecoder ($ this ->jsonDecoder );
610
+ $ curl ->setXmlDecoder ($ this ->xmlDecoder );
596
611
$ curl ->call ($ curl ->beforeSendFunction );
597
612
}
598
613
}
Original file line number Diff line number Diff line change @@ -1961,6 +1961,36 @@ public function testJSONDecoder()
1961
1961
$ this ->assertEquals ('bar ' , $ get_2 ->response );
1962
1962
}
1963
1963
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
+
1964
1994
public function testDownloadCallback ()
1965
1995
{
1966
1996
// Upload a file.
You can’t perform that action at this time.
0 commit comments