PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/includes/nusoap/lib/class.soap_parser.php

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