class.soap_parser.php 25 KB

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