server031.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --TEST--
  2. SOAP Server 31: Handling classes which implements Iterator
  3. --EXTENSIONS--
  4. soap
  5. --INI--
  6. soap.wsdl_cache_enabled=0
  7. --FILE--
  8. <?php
  9. class ItemArray implements Iterator {
  10. private $a = array();
  11. public function __construct(array $a) {
  12. $this->a = $a;
  13. }
  14. public function rewind(): void { reset($this->a); }
  15. public function current(): mixed { return current($this->a); }
  16. public function key(): mixed { return key($this->a); }
  17. public function next(): void { next($this->a); }
  18. public function valid(): bool { return (current($this->a) !== false); }
  19. }
  20. class Item {
  21. public $text;
  22. public function __construct($n) {
  23. $this->text = 'text'.$n;
  24. }
  25. }
  26. class handlerClass {
  27. public function getItems()
  28. {
  29. return new ItemArray(array(
  30. new Item(0),
  31. new Item(1),
  32. new Item(2),
  33. new Item(3),
  34. new Item(4),
  35. new Item(5),
  36. new Item(6),
  37. new Item(7),
  38. new Item(8),
  39. new Item(9)
  40. ));
  41. }
  42. }
  43. $server = new SoapServer(__DIR__."/server030.wsdl");
  44. $server->setClass('handlerClass');
  45. $HTTP_RAW_POST_DATA = <<<EOF
  46. <?xml version="1.0" encoding="ISO-8859-1"?>
  47. <SOAP-ENV:Envelope
  48. SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  49. xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  50. <SOAP-ENV:Body>
  51. <getItems/>
  52. </SOAP-ENV:Body>
  53. </SOAP-ENV:Envelope>
  54. EOF;
  55. $server->handle($HTTP_RAW_POST_DATA);
  56. echo "ok\n";
  57. ?>
  58. --EXPECT--
  59. <?xml version="1.0" encoding="UTF-8"?>
  60. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://testuri.org" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getItemsResponse><getItemsReturn SOAP-ENC:arrayType="ns1:Item[10]" xsi:type="ns1:ItemArray"><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text0</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text1</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text2</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text3</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text4</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text5</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text6</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text7</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text8</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text9</text></item></getItemsReturn></ns1:getItemsResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
  61. ok