class.soap_parser.php 25 KB

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