| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
class soap_parser extends nusoap_base { |
|---|
| 15 |
|
|---|
| 16 |
var $xml = ''; |
|---|
| 17 |
var $xml_encoding = ''; |
|---|
| 18 |
var $method = ''; |
|---|
| 19 |
var $root_struct = ''; |
|---|
| 20 |
var $root_struct_name = ''; |
|---|
| 21 |
var $root_struct_namespace = ''; |
|---|
| 22 |
var $root_header = ''; |
|---|
| 23 |
var $document = ''; |
|---|
| 24 |
|
|---|
| 25 |
var $status = ''; |
|---|
| 26 |
var $position = 0; |
|---|
| 27 |
var $depth = 0; |
|---|
| 28 |
var $default_namespace = ''; |
|---|
| 29 |
var $namespaces = array(); |
|---|
| 30 |
var $message = array(); |
|---|
| 31 |
var $parent = ''; |
|---|
| 32 |
var $fault = false; |
|---|
| 33 |
var $fault_code = ''; |
|---|
| 34 |
var $fault_str = ''; |
|---|
| 35 |
var $fault_detail = ''; |
|---|
| 36 |
var $depth_array = array(); |
|---|
| 37 |
var $debug_flag = true; |
|---|
| 38 |
var $soapresponse = NULL; |
|---|
| 39 |
var $responseHeaders = ''; |
|---|
| 40 |
var $body_position = 0; |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
var $ids = array(); |
|---|
| 44 |
|
|---|
| 45 |
var $multirefs = array(); |
|---|
| 46 |
|
|---|
| 47 |
var $decode_utf8 = true; |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
function soap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){ |
|---|
| 59 |
parent::nusoap_base(); |
|---|
| 60 |
$this->xml = $xml; |
|---|
| 61 |
$this->xml_encoding = $encoding; |
|---|
| 62 |
$this->method = $method; |
|---|
| 63 |
$this->decode_utf8 = $decode_utf8; |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
if(!empty($xml)){ |
|---|
| 67 |
|
|---|
| 68 |
$pos_xml = strpos($xml, '<?xml'); |
|---|
| 69 |
if ($pos_xml !== FALSE) { |
|---|
| 70 |
$xml_decl = substr($xml, $pos_xml, strpos($xml, '?>', $pos_xml + 2) - $pos_xml + 1); |
|---|
| 71 |
if (preg_match("/encoding=[\"']([^\"']*)[\"']/", $xml_decl, $res)) { |
|---|
| 72 |
$xml_encoding = $res[1]; |
|---|
| 73 |
if (strtoupper($xml_encoding) != $encoding) { |
|---|
| 74 |
$err = "Charset from HTTP Content-Type '" . $encoding . "' does not match encoding from XML declaration '" . $xml_encoding . "'"; |
|---|
| 75 |
$this->debug($err); |
|---|
| 76 |
if ($encoding != 'ISO-8859-1' || strtoupper($xml_encoding) != 'UTF-8') { |
|---|
| 77 |
$this->setError($err); |
|---|
| 78 |
return; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
} else { |
|---|
| 82 |
$this->debug('Charset from HTTP Content-Type matches encoding from XML declaration'); |
|---|
| 83 |
} |
|---|
| 84 |
} else { |
|---|
| 85 |
$this->debug('No encoding specified in XML declaration'); |
|---|
| 86 |
} |
|---|
| 87 |
} else { |
|---|
| 88 |
$this->debug('No XML declaration'); |
|---|
| 89 |
} |
|---|
| 90 |
$this->debug('Entering soap_parser(), length='.strlen($xml).', encoding='.$encoding); |
|---|
| 91 |
|
|---|
| 92 |
$this->parser = xml_parser_create($this->xml_encoding); |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); |
|---|
| 96 |
xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding); |
|---|
| 97 |
|
|---|
| 98 |
xml_set_object($this->parser, $this); |
|---|
| 99 |
|
|---|
| 100 |
xml_set_element_handler($this->parser, 'start_element','end_element'); |
|---|
| 101 |
xml_set_character_data_handler($this->parser,'character_data'); |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
if(!xml_parse($this->parser,$xml,true)){ |
|---|
| 105 |
|
|---|
| 106 |
$err = sprintf('XML error parsing SOAP payload on line %d: %s', |
|---|
| 107 |
xml_get_current_line_number($this->parser), |
|---|
| 108 |
xml_error_string(xml_get_error_code($this->parser))); |
|---|
| 109 |
$this->debug($err); |
|---|
| 110 |
$this->debug("XML payload:\n" . $xml); |
|---|
| 111 |
$this->setError($err); |
|---|
| 112 |
} else { |
|---|
| 113 |
$this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name); |
|---|
| 114 |
|
|---|
| 115 |
$this->soapresponse = $this->message[$this->root_struct]['result']; |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
if(sizeof($this->multirefs) > 0){ |
|---|
| 122 |
foreach($this->multirefs as $id => $hrefs){ |
|---|
| 123 |
$this->debug('resolving multirefs for id: '.$id); |
|---|
| 124 |
$idVal = $this->buildVal($this->ids[$id]); |
|---|
| 125 |
if (is_array($idVal) && isset($idVal['!id'])) { |
|---|
| 126 |
unset($idVal['!id']); |
|---|
| 127 |
} |
|---|
| 128 |
foreach($hrefs as $refPos => $ref){ |
|---|
| 129 |
$this->debug('resolving href at pos '.$refPos); |
|---|
| 130 |
$this->multirefs[$id][$refPos] = $idVal; |
|---|
| 131 |
} |
|---|
| 132 |
} |
|---|
| 133 |
} |
|---|
| 134 |
} |
|---|
| 135 |
xml_parser_free($this->parser); |
|---|
| 136 |
} else { |
|---|
| 137 |
$this->debug('xml was empty, didn\'t parse!'); |
|---|
| 138 |
$this->setError('xml was empty, didn\'t parse!'); |
|---|
| 139 |
} |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
function start_element($parser, $name, $attrs) { |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
$pos = $this->position++; |
|---|
| 154 |
|
|---|
| 155 |
$this->message[$pos] = array('pos' => $pos,'children'=>'','cdata'=>''); |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
$this->message[$pos]['depth'] = $this->depth++; |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
if($pos != 0){ |
|---|
| 162 |
$this->message[$this->parent]['children'] .= '|'.$pos; |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
$this->message[$pos]['parent'] = $this->parent; |
|---|
| 166 |
|
|---|
| 167 |
$this->parent = $pos; |
|---|
| 168 |
|
|---|
| 169 |
$this->depth_array[$this->depth] = $pos; |
|---|
| 170 |
|
|---|
| 171 |
if(strpos($name,':')){ |
|---|
| 172 |
|
|---|
| 173 |
$prefix = substr($name,0,strpos($name,':')); |
|---|
| 174 |
|
|---|
| 175 |
$name = substr(strstr($name,':'),1); |
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
if($name == 'Envelope'){ |
|---|
| 179 |
$this->status = 'envelope'; |
|---|
| 180 |
} elseif($name == 'Header'){ |
|---|
| 181 |
$this->root_header = $pos; |
|---|
| 182 |
$this->status = 'header'; |
|---|
| 183 |
} elseif($name == 'Body'){ |
|---|
| 184 |
$this->status = 'body'; |
|---|
| 185 |
$this->body_position = $pos; |
|---|
| 186 |
|
|---|
| 187 |
} elseif($this->status == 'body' && $pos == ($this->body_position+1)){ |
|---|
| 188 |
$this->status = 'method'; |
|---|
| 189 |
$this->root_struct_name = $name; |
|---|
| 190 |
$this->root_struct = $pos; |
|---|
| 191 |
$this->message[$pos]['type'] = 'struct'; |
|---|
| 192 |
$this->debug("found root struct $this->root_struct_name, pos $this->root_struct"); |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
$this->message[$pos]['status'] = $this->status; |
|---|
| 196 |
|
|---|
| 197 |
$this->message[$pos]['name'] = htmlspecialchars($name); |
|---|
| 198 |
|
|---|
| 199 |
$this->message[$pos]['attrs'] = $attrs; |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
$attstr = ''; |
|---|
| 203 |
foreach($attrs as $key => $value){ |
|---|
| 204 |
$key_prefix = $this->getPrefix($key); |
|---|
| 205 |
$key_localpart = $this->getLocalPart($key); |
|---|
| 206 |
|
|---|
| 207 |
if($key_prefix == 'xmlns'){ |
|---|
| 208 |
if(ereg('^http://www.w3.org/[0-9]{4}/XMLSchema$',$value)){ |
|---|
| 209 |
$this->XMLSchemaVersion = $value; |
|---|
| 210 |
$this->namespaces['xsd'] = $this->XMLSchemaVersion; |
|---|
| 211 |
$this->namespaces['xsi'] = $this->XMLSchemaVersion.'-instance'; |
|---|
| 212 |
} |
|---|
| 213 |
$this->namespaces[$key_localpart] = $value; |
|---|
| 214 |
|
|---|
| 215 |
if($name == $this->root_struct_name){ |
|---|
| 216 |
$this->methodNamespace = $value; |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
} elseif($key_localpart == 'type'){ |
|---|
| 220 |
$value_prefix = $this->getPrefix($value); |
|---|
| 221 |
$value_localpart = $this->getLocalPart($value); |
|---|
| 222 |
$this->message[$pos]['type'] = $value_localpart; |
|---|
| 223 |
$this->message[$pos]['typePrefix'] = $value_prefix; |
|---|
| 224 |
if(isset($this->namespaces[$value_prefix])){ |
|---|
| 225 |
$this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix]; |
|---|
| 226 |
} else if(isset($attrs['xmlns:'.$value_prefix])) { |
|---|
| 227 |
$this->message[$pos]['type_namespace'] = $attrs['xmlns:'.$value_prefix]; |
|---|
| 228 |
} |
|---|
| 229 |
|
|---|
| 230 |
} elseif($key_localpart == 'arrayType'){ |
|---|
| 231 |
$this->message[$pos]['type'] = 'array'; |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
$expr = '([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]'; |
|---|
| 241 |
if(ereg($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 |
|
|---|
| 254 |
} elseif ($key_localpart == 'nil'){ |
|---|
| 255 |
$this->message[$pos]['nil'] = ($value == 'true' || $value == '1'); |
|---|
| 256 |
|
|---|
| 257 |
} elseif ($key != 'href' && $key != 'xmlns' && $key_localpart != 'encodingStyle' && $key_localpart != 'root') { |
|---|
| 258 |
$this->message[$pos]['xattrs']['!' . $key] = $value; |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
if ($key == 'xmlns') { |
|---|
| 262 |
$this->default_namespace = $value; |
|---|
| 263 |
} |
|---|
| 264 |
|
|---|
| 265 |
if($key == 'id'){ |
|---|
| 266 |
$this->ids[$value] = $pos; |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
if($key_localpart == 'root' && $value == 1){ |
|---|
| 270 |
$this->status = 'method'; |
|---|
| 271 |
$this->root_struct_name = $name; |
|---|
| 272 |
$this->root_struct = $pos; |
|---|
| 273 |
$this->debug("found root struct $this->root_struct_name, pos $pos"); |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
$attstr .= " $key=\"$value\""; |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
if(isset($prefix)){ |
|---|
| 280 |
$this->message[$pos]['namespace'] = $this->namespaces[$prefix]; |
|---|
| 281 |
$this->default_namespace = $this->namespaces[$prefix]; |
|---|
| 282 |
} else { |
|---|
| 283 |
$this->message[$pos]['namespace'] = $this->default_namespace; |
|---|
| 284 |
} |
|---|
| 285 |
if($this->status == 'header'){ |
|---|
| 286 |
if ($this->root_header != $pos) { |
|---|
| 287 |
$this->responseHeaders .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>"; |
|---|
| 288 |
} |
|---|
| 289 |
} elseif($this->root_struct_name != ''){ |
|---|
| 290 |
$this->document .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>"; |
|---|
| 291 |
} |
|---|
| 292 |
} |
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
function end_element($parser, $name) { |
|---|
| 302 |
|
|---|
| 303 |
$pos = $this->depth_array[$this->depth--]; |
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
if(strpos($name,':')){ |
|---|
| 307 |
|
|---|
| 308 |
$prefix = substr($name,0,strpos($name,':')); |
|---|
| 309 |
|
|---|
| 310 |
$name = substr(strstr($name,':'),1); |
|---|
| 311 |
} |
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
if(isset($this->body_position) && $pos > $this->body_position){ |
|---|
| 315 |
|
|---|
| 316 |
if(isset($this->message[$pos]['attrs']['href'])){ |
|---|
| 317 |
|
|---|
| 318 |
$id = substr($this->message[$pos]['attrs']['href'],1); |
|---|
| 319 |
|
|---|
| 320 |
$this->multirefs[$id][$pos] = 'placeholder'; |
|---|
| 321 |
|
|---|
| 322 |
$this->message[$pos]['result'] =& $this->multirefs[$id][$pos]; |
|---|
| 323 |
|
|---|
| 324 |
} elseif($this->message[$pos]['children'] != ''){ |
|---|
| 325 |
|
|---|
| 326 |
if(!isset($this->message[$pos]['result'])){ |
|---|
| 327 |
$this->message[$pos]['result'] = $this->buildVal($pos); |
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
} elseif (isset($this->message[$pos]['xattrs'])) { |
|---|
| 331 |
if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) { |
|---|
| 332 |
$this->message[$pos]['xattrs']['!'] = null; |
|---|
| 333 |
} elseif (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') { |
|---|
| 334 |
if (isset($this->message[$pos]['type'])) { |
|---|
| 335 |
$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'] : ''); |
|---|
| 336 |
} else { |
|---|
| 337 |
$parent = $this->message[$pos]['parent']; |
|---|
| 338 |
if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) { |
|---|
| 339 |
$this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : ''); |
|---|
| 340 |
} else { |
|---|
| 341 |
$this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata']; |
|---|
| 342 |
} |
|---|
| 343 |
} |
|---|
| 344 |
} |
|---|
| 345 |
$this->message[$pos]['result'] = $this->message[$pos]['xattrs']; |
|---|
| 346 |
|
|---|
| 347 |
} else { |
|---|
| 348 |
|
|---|
| 349 |
if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) { |
|---|
| 350 |
$this->message[$pos]['xattrs']['!'] = null; |
|---|
| 351 |
} elseif (isset($this->message[$pos]['type'])) { |
|---|
| 352 |
$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'] : ''); |
|---|
| 353 |
} else { |
|---|
| 354 |
$parent = $this->message[$pos]['parent']; |
|---|
| 355 |
if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) { |
|---|
| 356 |
$this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : ''); |
|---|
| 357 |
} else { |
|---|
| 358 |
$this->message[$pos]['result'] = $this->message[$pos]['cdata']; |
|---|
| 359 |
} |
|---|
| 360 |
} |
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
} |
|---|
| 373 |
} |
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
if($this->status == 'header'){ |
|---|
| 377 |
if ($this->root_header != $pos) { |
|---|
| 378 |
$this->responseHeaders .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>"; |
|---|
| 379 |
} |
|---|
| 380 |
} elseif($pos >= $this->root_struct){ |
|---|
| 381 |
$this->document .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>"; |
|---|
| 382 |
} |
|---|
| 383 |
|
|---|
| 384 |
if($pos == $this->root_struct){ |
|---|
| 385 |
$this->status = 'body'; |
|---|
| 386 |
$this->root_struct_namespace = $this->message[$pos]['namespace']; |
|---|
| 387 |
} elseif($name == 'Body'){ |
|---|
| 388 |
$this->status = 'envelope'; |
|---|
| 389 |
} elseif($name == 'Header'){ |
|---|
| 390 |
$this->status = 'envelope'; |
|---|
| 391 |
} elseif($name == 'Envelope'){ |
|---|
| 392 |
|
|---|
| 393 |
} |
|---|
| 394 |
|
|---|
| 395 |
$this->parent = $this->message[$pos]['parent']; |
|---|
| 396 |
} |
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
|
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
function character_data($parser, $data){ |
|---|
| 406 |
$pos = $this->depth_array[$this->depth]; |
|---|
| 407 |
if ($this->xml_encoding=='UTF-8'){ |
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
if($this->decode_utf8){ |
|---|
| 412 |
$data = utf8_decode($data); |
|---|
| 413 |
} |
|---|
| 414 |
} |
|---|
| 415 |
$this->message[$pos]['cdata'] .= $data; |
|---|
| 416 |
|
|---|
| 417 |
if($this->status == 'header'){ |
|---|
| 418 |
$this->responseHeaders .= $data; |
|---|
| 419 |
} else { |
|---|
| 420 |
$this->document .= $data; |
|---|
| 421 |
} |
|---|
| 422 |
} |
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
function get_response(){ |
|---|
| 431 |
return $this->soapresponse; |
|---|
| 432 |
} |
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
|
|---|
| 440 |
function getHeaders(){ |
|---|
| 441 |
return $this->responseHeaders; |
|---|
| 442 |
} |
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
function decodeSimple($value, $type, $typens) { |
|---|
| 454 |
|
|---|
| 455 |
if ((!isset($type)) || $type == 'string' || $type == 'long' || $type == 'unsignedLong') { |
|---|
| 456 |
return (string) $value; |
|---|
| 457 |
} |
|---|
| 458 |
if ($type == 'int' || $type == 'integer' || $type == 'short' || $type == 'byte') { |
|---|
| 459 |
return (int) $value; |
|---|
| 460 |
} |
|---|
| 461 |
if ($type == 'float' || $type == 'double' || $type == 'decimal') { |
|---|
| 462 |
return (double) $value; |
|---|
| 463 |
} |
|---|
| 464 |
if ($type == 'boolean') { |
|---|
| 465 |
if (strtolower($value) == 'false' || strtolower($value) == 'f') { |
|---|
| 466 |
return false; |
|---|
| 467 |
} |
|---|
| 468 |
return (boolean) $value; |
|---|
| 469 |
} |
|---|
| 470 |
if ($type == 'base64' || $type == 'base64Binary') { |
|---|
| 471 |
$this->debug('Decode base64 value'); |
|---|
| 472 |
return base64_decode($value); |
|---|
| 473 |
} |
|---|
| 474 |
|
|---|
| 475 |
if ($type == 'nonPositiveInteger' || $type == 'negativeInteger' |
|---|
| 476 |
|| $type == 'nonNegativeInteger' || $type == 'positiveInteger' |
|---|
| 477 |
|| $type == 'unsignedInt' |
|---|
| 478 |
|| $type == 'unsignedShort' || $type == 'unsignedByte') { |
|---|
| 479 |
return (int) $value; |
|---|
| 480 |
} |
|---|
| 481 |
|
|---|
| 482 |
if ($type == 'array') { |
|---|
| 483 |
return array(); |
|---|
| 484 |
} |
|---|
| 485 |
|
|---|
| 486 |
return (string) $value; |
|---|
| 487 |
} |
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
function buildVal($pos){ |
|---|
| 498 |
if(!isset($this->message[$pos]['type'])){ |
|---|
| 499 |
$this->message[$pos]['type'] = ''; |
|---|
| 500 |
} |
|---|
| 501 |
$this->debug('in buildVal() for '.$this->message[$pos]['name']."(pos $pos) of type ".$this->message[$pos]['type']); |
|---|
| 502 |
|
|---|
| 503 |
if($this->message[$pos]['children'] != ''){ |
|---|
| 504 |
$this->debug('in buildVal, there are children'); |
|---|
| 505 |
$children = explode('|',$this->message[$pos]['children']); |
|---|
| 506 |
array_shift($children); |
|---|
| 507 |
|
|---|
| 508 |
if(isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != ''){ |
|---|
| 509 |
$r=0; |
|---|
| 510 |
$c=0; |
|---|
| 511 |
foreach($children as $child_pos){ |
|---|
| 512 |
$this->debug("in buildVal, got an MD array element: $r, $c"); |
|---|
| 513 |
$params[$r][] = $this->message[$child_pos]['result']; |
|---|
| 514 |
$c++; |
|---|
| 515 |
if($c == $this->message[$pos]['arrayCols']){ |
|---|
| 516 |
$c = 0; |
|---|
| 517 |
$r++; |
|---|
| 518 |
} |
|---|
| 519 |
} |
|---|
| 520 |
|
|---|
| 521 |
} elseif($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array'){ |
|---|
| 522 |
$this->debug('in buildVal, adding array '.$this->message[$pos]['name']); |
|---|
| 523 |
foreach($children as $child_pos){ |
|---|
| 524 |
$params[] = &$this->message[$child_pos]['result']; |
|---|
| 525 |
} |
|---|
| 526 |
|
|---|
| 527 |
} elseif($this->message[$pos]['type'] == 'Map' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap'){ |
|---|
| 528 |
$this->debug('in buildVal, Java Map '.$this->message[$pos]['name']); |
|---|
| 529 |
foreach($children as $child_pos){ |
|---|
| 530 |
$kv = explode("|",$this->message[$child_pos]['children']); |
|---|
| 531 |
$params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result']; |
|---|
| 532 |
} |
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
} else { |
|---|
| 536 |
|
|---|
| 537 |
$this->debug('in buildVal, adding Java Vector '.$this->message[$pos]['name']); |
|---|
| 538 |
if ($this->message[$pos]['type'] == 'Vector' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') { |
|---|
| 539 |
$notstruct = 1; |
|---|
| 540 |
} else { |
|---|
| 541 |
$notstruct = 0; |
|---|
| 542 |
} |
|---|
| 543 |
|
|---|
| 544 |
foreach($children as $child_pos){ |
|---|
| 545 |
if($notstruct){ |
|---|
| 546 |
$params[] = &$this->message[$child_pos]['result']; |
|---|
| 547 |
} else { |
|---|
| 548 |
if (isset($params[$this->message[$child_pos]['name']])) { |
|---|
| 549 |
|
|---|
| 550 |
if ((!is_array($params[$this->message[$child_pos]['name']])) || (!isset($params[$this->message[$child_pos]['name']][0]))) { |
|---|
| 551 |
$params[$this->message[$child_pos]['name']] = array($params[$this->message[$child_pos]['name']]); |
|---|
| 552 |
} |
|---|
| 553 |
$params[$this->message[$child_pos]['name']][] = &$this->message[$child_pos]['result']; |
|---|
| 554 |
} else { |
|---|
| 555 |
$params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result']; |
|---|
| 556 |
} |
|---|
| 557 |
} |
|---|
| 558 |
} |
|---|
| 559 |
} |
|---|
| 560 |
if (isset($this->message[$pos]['xattrs'])) { |
|---|
| 561 |
$this->debug('in buildVal, handling attributes'); |
|---|
| 562 |
foreach ($this->message[$pos]['xattrs'] as $n => $v) { |
|---|
| 563 |
$params[$n] = $v; |
|---|
| 564 |
} |
|---|
| 565 |
} |
|---|
| 566 |
|
|---|
| 567 |
if (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') { |
|---|
| 568 |
$this->debug('in buildVal, handling simpleContent'); |
|---|
| 569 |
if (isset($this->message[$pos]['type'])) { |
|---|
| 570 |
$params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : ''); |
|---|
| 571 |
} else { |
|---|
| 572 |
$parent = $this->message[$pos]['parent']; |
|---|
| 573 |
if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) { |
|---|
| 574 |
$params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : ''); |
|---|
| 575 |
} else { |
|---|
| 576 |
$params['!'] = $this->message[$pos]['cdata']; |
|---|
| 577 |
} |
|---|
| 578 |
} |
|---|
| 579 |
} |
|---|
| 580 |
return is_array($params) ? $params : array(); |
|---|
| 581 |
} else { |
|---|
| 582 |
$this->debug('in buildVal, no children, building scalar'); |
|---|
| 583 |
$cdata = isset($this->message[$pos]['cdata']) ? $this->message[$pos]['cdata'] : ''; |
|---|
| 584 |
if (isset($this->message[$pos]['type'])) { |
|---|
| 585 |
return $this->decodeSimple($cdata, $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : ''); |
|---|
| 586 |
} |
|---|
| 587 |
$parent = $this->message[$pos]['parent']; |
|---|
| 588 |
if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) { |
|---|
| 589 |
return $this->decodeSimple($cdata, $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : ''); |
|---|
| 590 |
} |
|---|
| 591 |
return $this->message[$pos]['cdata']; |
|---|
| 592 |
} |
|---|
| 593 |
} |
|---|
| 594 |
} |
|---|
| 595 |
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
?> |
|---|