class.soap_parser.php 25 KB

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