class.soap_parser.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <?php
  2. /**
  3. *
  4. * nusoap_parser class parses SOAP XML messages into native PHP values
  5. *
  6. * @author Dietrich Ayala <dietrich@ganx4.com>
  7. * @author Scott Nichol <snichol@users.sourceforge.net>
  8. * @version $Id: class.soap_parser.php,v 1.40 2007/04/17 16:34:03 snichol Exp $
  9. * @access public
  10. */
  11. class nusoap_parser extends nusoap_base {
  12. var $xml = '';
  13. var $xml_encoding = '';
  14. var $method = '';
  15. var $root_struct = '';
  16. var $root_struct_name = '';
  17. var $root_struct_namespace = '';
  18. var $root_header = '';
  19. var $document = ''; // incoming SOAP body (text)
  20. // determines where in the message we are (envelope,header,body,method)
  21. var $status = '';
  22. var $position = 0;
  23. var $depth = 0;
  24. var $default_namespace = '';
  25. var $namespaces = array();
  26. var $message = array();
  27. var $parent = '';
  28. var $fault = false;
  29. var $fault_code = '';
  30. var $fault_str = '';
  31. var $fault_detail = '';
  32. var $depth_array = array();
  33. var $debug_flag = true;
  34. var $soapresponse = NULL; // parsed SOAP Body
  35. var $soapheader = NULL; // parsed SOAP Header
  36. var $responseHeaders = ''; // incoming SOAP headers (text)
  37. var $body_position = 0;
  38. // for multiref parsing:
  39. // array of id => pos
  40. var $ids = array();
  41. // array of id => hrefs => pos
  42. var $multirefs = array();
  43. // toggle for auto-decoding element content
  44. var $decode_utf8 = true;
  45. /**
  46. * constructor that actually does the parsing
  47. *
  48. * @param string $xml SOAP message
  49. * @param string $encoding character encoding scheme of message
  50. * @param string $method method for which XML is parsed (unused?)
  51. * @param string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
  52. * @access public
  53. */
  54. function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){
  55. parent::nusoap_base();
  56. $this->xml = $xml;
  57. $this->xml_encoding = $encoding;
  58. $this->method = $method;
  59. $this->decode_utf8 = $decode_utf8;
  60. // Check whether content has been read.
  61. if(!empty($xml)){
  62. // Check XML encoding
  63. $pos_xml = strpos($xml, '<?xml');
  64. if ($pos_xml !== FALSE) {
  65. $xml_decl = substr($xml, $pos_xml, strpos($xml, '?>', $pos_xml + 2) - $pos_xml + 1);
  66. if (preg_match("/encoding=[\"']([^\"']*)[\"']/", $xml_decl, $res)) {
  67. $xml_encoding = $res[1];
  68. if (strtoupper($xml_encoding) != $encoding) {
  69. $err = "Charset from HTTP Content-Type '" . $encoding . "' does not match encoding from XML declaration '" . $xml_encoding . "'";
  70. $this->debug($err);
  71. if ($encoding != 'ISO-8859-1' || strtoupper($xml_encoding) != 'UTF-8') {
  72. $this->setError($err);
  73. return;
  74. }
  75. // when HTTP says ISO-8859-1 (the default) and XML says UTF-8 (the typical), assume the other endpoint is just sloppy and proceed
  76. } else {
  77. $this->debug('Charset from HTTP Content-Type matches encoding from XML declaration');
  78. }
  79. } else {
  80. $this->debug('No encoding specified in XML declaration');
  81. }
  82. } else {
  83. $this->debug('No XML declaration');
  84. }
  85. $this->debug('Entering nusoap_parser(), length='.strlen($xml).', encoding='.$encoding);
  86. // Create an XML parser - why not xml_parser_create_ns?
  87. $this->parser = xml_parser_create($this->xml_encoding);
  88. // Set the options for parsing the XML data.
  89. //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  90. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  91. xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
  92. // Set the object for the parser.
  93. xml_set_object($this->parser, $this);
  94. // Set the element handlers for the parser.
  95. xml_set_element_handler($this->parser, 'start_element','end_element');
  96. xml_set_character_data_handler($this->parser,'character_data');
  97. // Parse the XML file.
  98. if(!xml_parse($this->parser,$xml,true)){
  99. // Display an error message.
  100. $err = sprintf('XML error parsing SOAP payload on line %d: %s',
  101. xml_get_current_line_number($this->parser),
  102. xml_error_string(xml_get_error_code($this->parser)));
  103. $this->debug($err);
  104. $this->debug("XML payload:\n" . $xml);
  105. $this->setError($err);
  106. } else {
  107. $this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name);
  108. // get final value
  109. $this->soapresponse = $this->message[$this->root_struct]['result'];
  110. // get header value
  111. if($this->root_header != '' && isset($this->message[$this->root_header]['result'])){
  112. $this->soapheader = $this->message[$this->root_header]['result'];
  113. }
  114. // resolve hrefs/ids
  115. if(sizeof($this->multirefs) > 0){
  116. foreach($this->multirefs as $id => $hrefs){
  117. $this->debug('resolving multirefs for id: '.$id);
  118. $idVal = $this->buildVal($this->ids[$id]);
  119. if (is_array($idVal) && isset($idVal['!id'])) {
  120. unset($idVal['!id']);
  121. }
  122. foreach($hrefs as $refPos => $ref){
  123. $this->debug('resolving href at pos '.$refPos);
  124. $this->multirefs[$id][$refPos] = $idVal;
  125. }
  126. }
  127. }
  128. }
  129. xml_parser_free($this->parser);
  130. } else {
  131. $this->debug('xml was empty, didn\'t parse!');
  132. $this->setError('xml was empty, didn\'t parse!');
  133. }
  134. }
  135. /**
  136. * start-element handler
  137. *
  138. * @param resource $parser XML parser object
  139. * @param string $name element name
  140. * @param array $attrs associative array of attributes
  141. * @access private
  142. */
  143. function start_element($parser, $name, $attrs) {
  144. // position in a total number of elements, starting from 0
  145. // update class level pos
  146. $pos = $this->position++;
  147. // and set mine
  148. $this->message[$pos] = array('pos' => $pos,'children'=>'','cdata'=>'');
  149. // depth = how many levels removed from root?
  150. // set mine as current global depth and increment global depth value
  151. $this->message[$pos]['depth'] = $this->depth++;
  152. // else add self as child to whoever the current parent is
  153. if($pos != 0){
  154. $this->message[$this->parent]['children'] .= '|'.$pos;
  155. }
  156. // set my parent
  157. $this->message[$pos]['parent'] = $this->parent;
  158. // set self as current parent
  159. $this->parent = $pos;
  160. // set self as current value for this depth
  161. $this->depth_array[$this->depth] = $pos;
  162. // get element prefix
  163. if(strpos($name,':')){
  164. // get ns prefix
  165. $prefix = substr($name,0,strpos($name,':'));
  166. // get unqualified name
  167. $name = substr(strstr($name,':'),1);
  168. }
  169. // set status
  170. if($name == 'Envelope'){
  171. $this->status = 'envelope';
  172. } elseif($name == 'Header' && $this->status = 'envelope'){
  173. $this->root_header = $pos;
  174. $this->status = 'header';
  175. } elseif($name == 'Body' && $this->status = 'envelope'){
  176. $this->status = 'body';
  177. $this->body_position = $pos;
  178. // set method
  179. } elseif($this->status == 'body' && $pos == ($this->body_position+1)){
  180. $this->status = 'method';
  181. $this->root_struct_name = $name;
  182. $this->root_struct = $pos;
  183. $this->message[$pos]['type'] = 'struct';
  184. $this->debug("found root struct $this->root_struct_name, pos $this->root_struct");
  185. }
  186. // set my status
  187. $this->message[$pos]['status'] = $this->status;
  188. // set name
  189. $this->message[$pos]['name'] = htmlspecialchars($name);
  190. // set attrs
  191. $this->message[$pos]['attrs'] = $attrs;
  192. // loop through atts, logging ns and type declarations
  193. $attstr = '';
  194. foreach($attrs as $key => $value){
  195. $key_prefix = $this->getPrefix($key);
  196. $key_localpart = $this->getLocalPart($key);
  197. // if ns declarations, add to class level array of valid namespaces
  198. if($key_prefix == 'xmlns'){
  199. if(ereg('^http://www.w3.org/[0-9]{4}/XMLSchema$',$value)){
  200. $this->XMLSchemaVersion = $value;
  201. $this->namespaces['xsd'] = $this->XMLSchemaVersion;
  202. $this->namespaces['xsi'] = $this->XMLSchemaVersion.'-instance';
  203. }
  204. $this->namespaces[$key_localpart] = $value;
  205. // set method namespace
  206. if($name == $this->root_struct_name){
  207. $this->methodNamespace = $value;
  208. }
  209. // if it's a type declaration, set type
  210. } elseif($key_localpart == 'type'){
  211. if (isset($this->message[$pos]['type']) && $this->message[$pos]['type'] == 'array') {
  212. // do nothing: already processed arrayType
  213. } else {
  214. $value_prefix = $this->getPrefix($value);
  215. $value_localpart = $this->getLocalPart($value);
  216. $this->message[$pos]['type'] = $value_localpart;
  217. $this->message[$pos]['typePrefix'] = $value_prefix;
  218. if(isset($this->namespaces[$value_prefix])){
  219. $this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix];
  220. } else if(isset($attrs['xmlns:'.$value_prefix])) {
  221. $this->message[$pos]['type_namespace'] = $attrs['xmlns:'.$value_prefix];
  222. }
  223. // should do something here with the namespace of specified type?
  224. }
  225. } elseif($key_localpart == 'arrayType'){
  226. $this->message[$pos]['type'] = 'array';
  227. /* do arrayType ereg here
  228. [1] arrayTypeValue ::= atype asize
  229. [2] atype ::= QName rank*
  230. [3] rank ::= '[' (',')* ']'
  231. [4] asize ::= '[' length~ ']'
  232. [5] length ::= nextDimension* Digit+
  233. [6] nextDimension ::= Digit+ ','
  234. */
  235. $expr = '([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]';
  236. if(ereg($expr,$value,$regs)){
  237. $this->message[$pos]['typePrefix'] = $regs[1];
  238. $this->message[$pos]['arrayTypePrefix'] = $regs[1];
  239. if (isset($this->namespaces[$regs[1]])) {
  240. $this->message[$pos]['arrayTypeNamespace'] = $this->namespaces[$regs[1]];
  241. } else if (isset($attrs['xmlns:'.$regs[1]])) {
  242. $this->message[$pos]['arrayTypeNamespace'] = $attrs['xmlns:'.$regs[1]];
  243. }
  244. $this->message[$pos]['arrayType'] = $regs[2];
  245. $this->message[$pos]['arraySize'] = $regs[3];
  246. $this->message[$pos]['arrayCols'] = $regs[4];
  247. }
  248. // specifies nil value (or not)
  249. } elseif ($key_localpart == 'nil'){
  250. $this->message[$pos]['nil'] = ($value == 'true' || $value == '1');
  251. // some other attribute
  252. } elseif ($key != 'href' && $key != 'xmlns' && $key_localpart != 'encodingStyle' && $key_localpart != 'root') {
  253. $this->message[$pos]['xattrs']['!' . $key] = $value;
  254. }
  255. if ($key == 'xmlns') {
  256. $this->default_namespace = $value;
  257. }
  258. // log id
  259. if($key == 'id'){
  260. $this->ids[$value] = $pos;
  261. }
  262. // root
  263. if($key_localpart == 'root' && $value == 1){
  264. $this->status = 'method';
  265. $this->root_struct_name = $name;
  266. $this->root_struct = $pos;
  267. $this->debug("found root struct $this->root_struct_name, pos $pos");
  268. }
  269. // for doclit
  270. $attstr .= " $key=\"$value\"";
  271. }
  272. // get namespace - must be done after namespace atts are processed
  273. if(isset($prefix)){
  274. $this->message[$pos]['namespace'] = $this->namespaces[$prefix];
  275. $this->default_namespace = $this->namespaces[$prefix];
  276. } else {
  277. $this->message[$pos]['namespace'] = $this->default_namespace;
  278. }
  279. if($this->status == 'header'){
  280. if ($this->root_header != $pos) {
  281. $this->responseHeaders .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
  282. }
  283. } elseif($this->root_struct_name != ''){
  284. $this->document .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
  285. }
  286. }
  287. /**
  288. * end-element handler
  289. *
  290. * @param resource $parser XML parser object
  291. * @param string $name element name
  292. * @access private
  293. */
  294. function end_element($parser, $name) {
  295. // position of current element is equal to the last value left in depth_array for my depth
  296. $pos = $this->depth_array[$this->depth--];
  297. // get element prefix
  298. if(strpos($name,':')){
  299. // get ns prefix
  300. $prefix = substr($name,0,strpos($name,':'));
  301. // get unqualified name
  302. $name = substr(strstr($name,':'),1);
  303. }
  304. // build to native type
  305. if(isset($this->body_position) && $pos > $this->body_position){
  306. // deal w/ multirefs
  307. if(isset($this->message[$pos]['attrs']['href'])){
  308. // get id
  309. $id = substr($this->message[$pos]['attrs']['href'],1);
  310. // add placeholder to href array
  311. $this->multirefs[$id][$pos] = 'placeholder';
  312. // add set a reference to it as the result value
  313. $this->message[$pos]['result'] =& $this->multirefs[$id][$pos];
  314. // build complexType values
  315. } elseif($this->message[$pos]['children'] != ''){
  316. // if result has already been generated (struct/array)
  317. if(!isset($this->message[$pos]['result'])){
  318. $this->message[$pos]['result'] = $this->buildVal($pos);
  319. }
  320. // build complexType values of attributes and possibly simpleContent
  321. } elseif (isset($this->message[$pos]['xattrs'])) {
  322. if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
  323. $this->message[$pos]['xattrs']['!'] = null;
  324. } elseif (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
  325. if (isset($this->message[$pos]['type'])) {
  326. $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
  327. } else {
  328. $parent = $this->message[$pos]['parent'];
  329. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  330. $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  331. } else {
  332. $this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata'];
  333. }
  334. }
  335. }
  336. $this->message[$pos]['result'] = $this->message[$pos]['xattrs'];
  337. // set value of simpleType (or nil complexType)
  338. } else {
  339. //$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);
  340. if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
  341. $this->message[$pos]['xattrs']['!'] = null;
  342. } elseif (isset($this->message[$pos]['type'])) {
  343. $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
  344. } else {
  345. $parent = $this->message[$pos]['parent'];
  346. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  347. $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  348. } else {
  349. $this->message[$pos]['result'] = $this->message[$pos]['cdata'];
  350. }
  351. }
  352. /* add value to parent's result, if parent is struct/array
  353. $parent = $this->message[$pos]['parent'];
  354. if($this->message[$parent]['type'] != 'map'){
  355. if(strtolower($this->message[$parent]['type']) == 'array'){
  356. $this->message[$parent]['result'][] = $this->message[$pos]['result'];
  357. } else {
  358. $this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result'];
  359. }
  360. }
  361. */
  362. }
  363. }
  364. // for doclit
  365. if($this->status == 'header'){
  366. if ($this->root_header != $pos) {
  367. $this->responseHeaders .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
  368. }
  369. } elseif($pos >= $this->root_struct){
  370. $this->document .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
  371. }
  372. // switch status
  373. if($pos == $this->root_struct){
  374. $this->status = 'body';
  375. $this->root_struct_namespace = $this->message[$pos]['namespace'];
  376. } elseif($name == 'Body'){
  377. $this->status = 'envelope';
  378. } elseif($name == 'Header'){
  379. $this->status = 'envelope';
  380. } elseif($name == 'Envelope'){
  381. //
  382. }
  383. // set parent back to my parent
  384. $this->parent = $this->message[$pos]['parent'];
  385. }
  386. /**
  387. * element content handler
  388. *
  389. * @param resource $parser XML parser object
  390. * @param string $data element content
  391. * @access private
  392. */
  393. function character_data($parser, $data){
  394. $pos = $this->depth_array[$this->depth];
  395. if ($this->xml_encoding=='UTF-8'){
  396. // TODO: add an option to disable this for folks who want
  397. // raw UTF-8 that, e.g., might not map to iso-8859-1
  398. // TODO: this can also be handled with xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
  399. if($this->decode_utf8){
  400. $data = utf8_decode($data);
  401. }
  402. }
  403. $this->message[$pos]['cdata'] .= $data;
  404. // for doclit
  405. if($this->status == 'header'){
  406. $this->responseHeaders .= $data;
  407. } else {
  408. $this->document .= $data;
  409. }
  410. }
  411. /**
  412. * get the parsed message (SOAP Body)
  413. *
  414. * @return mixed
  415. * @access public
  416. * @deprecated use get_soapbody instead
  417. */
  418. function get_response(){
  419. return $this->soapresponse;
  420. }
  421. /**
  422. * get the parsed SOAP Body (NULL if there was none)
  423. *
  424. * @return mixed
  425. * @access public
  426. */
  427. function get_soapbody(){
  428. return $this->soapresponse;
  429. }
  430. /**
  431. * get the parsed SOAP Header (NULL if there was none)
  432. *
  433. * @return mixed
  434. * @access public
  435. */
  436. function get_soapheader(){
  437. return $this->soapheader;
  438. }
  439. /**
  440. * get the unparsed SOAP Header
  441. *
  442. * @return string XML or empty if no Header
  443. * @access public
  444. */
  445. function getHeaders(){
  446. return $this->responseHeaders;
  447. }
  448. /**
  449. * decodes simple types into PHP variables
  450. *
  451. * @param string $value value to decode
  452. * @param string $type XML type to decode
  453. * @param string $typens XML type namespace to decode
  454. * @return mixed PHP value
  455. * @access private
  456. */
  457. function decodeSimple($value, $type, $typens) {
  458. // TODO: use the namespace!
  459. if ((!isset($type)) || $type == 'string' || $type == 'long' || $type == 'unsignedLong') {
  460. return (string) $value;
  461. }
  462. if ($type == 'int' || $type == 'integer' || $type == 'short' || $type == 'byte') {
  463. return (int) $value;
  464. }
  465. if ($type == 'float' || $type == 'double' || $type == 'decimal') {
  466. return (double) $value;
  467. }
  468. if ($type == 'boolean') {
  469. if (strtolower($value) == 'false' || strtolower($value) == 'f') {
  470. return false;
  471. }
  472. return (boolean) $value;
  473. }
  474. if ($type == 'base64' || $type == 'base64Binary') {
  475. $this->debug('Decode base64 value');
  476. return base64_decode($value);
  477. }
  478. // obscure numeric types
  479. if ($type == 'nonPositiveInteger' || $type == 'negativeInteger'
  480. || $type == 'nonNegativeInteger' || $type == 'positiveInteger'
  481. || $type == 'unsignedInt'
  482. || $type == 'unsignedShort' || $type == 'unsignedByte') {
  483. return (int) $value;
  484. }
  485. // bogus: parser treats array with no elements as a simple type
  486. if ($type == 'array') {
  487. return array();
  488. }
  489. // everything else
  490. return (string) $value;
  491. }
  492. /**
  493. * builds response structures for compound values (arrays/structs)
  494. * and scalars
  495. *
  496. * @param integer $pos position in node tree
  497. * @return mixed PHP value
  498. * @access private
  499. */
  500. function buildVal($pos){
  501. if(!isset($this->message[$pos]['type'])){
  502. $this->message[$pos]['type'] = '';
  503. }
  504. $this->debug('in buildVal() for '.$this->message[$pos]['name']."(pos $pos) of type ".$this->message[$pos]['type']);
  505. // if there are children...
  506. if($this->message[$pos]['children'] != ''){
  507. $this->debug('in buildVal, there are children');
  508. $children = explode('|',$this->message[$pos]['children']);
  509. array_shift($children); // knock off empty
  510. // md array
  511. if(isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != ''){
  512. $r=0; // rowcount
  513. $c=0; // colcount
  514. foreach($children as $child_pos){
  515. $this->debug("in buildVal, got an MD array element: $r, $c");
  516. $params[$r][] = $this->message[$child_pos]['result'];
  517. $c++;
  518. if($c == $this->message[$pos]['arrayCols']){
  519. $c = 0;
  520. $r++;
  521. }
  522. }
  523. // array
  524. } elseif($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array'){
  525. $this->debug('in buildVal, adding array '.$this->message[$pos]['name']);
  526. foreach($children as $child_pos){
  527. $params[] = &$this->message[$child_pos]['result'];
  528. }
  529. // apache Map type: java hashtable
  530. } elseif($this->message[$pos]['type'] == 'Map' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap'){
  531. $this->debug('in buildVal, Java Map '.$this->message[$pos]['name']);
  532. foreach($children as $child_pos){
  533. $kv = explode("|",$this->message[$child_pos]['children']);
  534. $params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result'];
  535. }
  536. // generic compound type
  537. //} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') {
  538. } else {
  539. // Apache Vector type: treat as an array
  540. $this->debug('in buildVal, adding Java Vector or generic compound type '.$this->message[$pos]['name']);
  541. if ($this->message[$pos]['type'] == 'Vector' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') {
  542. $notstruct = 1;
  543. } else {
  544. $notstruct = 0;
  545. }
  546. //
  547. foreach($children as $child_pos){
  548. if($notstruct){
  549. $params[] = &$this->message[$child_pos]['result'];
  550. } else {
  551. if (isset($params[$this->message[$child_pos]['name']])) {
  552. // de-serialize repeated element name into an array
  553. if ((!is_array($params[$this->message[$child_pos]['name']])) || (!isset($params[$this->message[$child_pos]['name']][0]))) {
  554. $params[$this->message[$child_pos]['name']] = array($params[$this->message[$child_pos]['name']]);
  555. }
  556. $params[$this->message[$child_pos]['name']][] = &$this->message[$child_pos]['result'];
  557. } else {
  558. $params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result'];
  559. }
  560. }
  561. }
  562. }
  563. if (isset($this->message[$pos]['xattrs'])) {
  564. $this->debug('in buildVal, handling attributes');
  565. foreach ($this->message[$pos]['xattrs'] as $n => $v) {
  566. $params[$n] = $v;
  567. }
  568. }
  569. // handle simpleContent
  570. if (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
  571. $this->debug('in buildVal, handling simpleContent');
  572. if (isset($this->message[$pos]['type'])) {
  573. $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
  574. } else {
  575. $parent = $this->message[$pos]['parent'];
  576. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  577. $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  578. } else {
  579. $params['!'] = $this->message[$pos]['cdata'];
  580. }
  581. }
  582. }
  583. $ret = is_array($params) ? $params : array();
  584. $this->debug('in buildVal, return:');
  585. $this->appendDebug($this->varDump($ret));
  586. return $ret;
  587. } else {
  588. $this->debug('in buildVal, no children, building scalar');
  589. $cdata = isset($this->message[$pos]['cdata']) ? $this->message[$pos]['cdata'] : '';
  590. if (isset($this->message[$pos]['type'])) {
  591. $ret = $this->decodeSimple($cdata, $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
  592. $this->debug("in buildVal, return: $ret");
  593. return $ret;
  594. }
  595. $parent = $this->message[$pos]['parent'];
  596. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  597. $ret = $this->decodeSimple($cdata, $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  598. $this->debug("in buildVal, return: $ret");
  599. return $ret;
  600. }
  601. $ret = $this->message[$pos]['cdata'];
  602. $this->debug("in buildVal, return: $ret");
  603. return $ret;
  604. }
  605. }
  606. }
  607. /**
  608. * Backward compatibility
  609. */
  610. class soap_parser extends nusoap_parser {
  611. }
  612. ?>