[ Index ]
 

Code source de nusoap 0.7.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/ -> class.soap_parser.php (source)

   1  <?php
   2  
   3  
   4  
   5  
   6  /**

   7  *

   8  * soap_parser class parses SOAP XML messages into native PHP values

   9  *

  10  * @author   Dietrich Ayala <dietrich@ganx4.com>

  11  * @version  $Id: class.soap_parser.php,v 1.36 2005/08/04 01:27:42 snichol Exp $

  12  * @access   public

  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 = '';            // incoming SOAP body (text)

  24      // determines where in the message we are (envelope,header,body,method)

  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 = '';    // incoming SOAP headers (text)

  40      var $body_position = 0;
  41      // for multiref parsing:

  42      // array of id => pos

  43      var $ids = array();
  44      // array of id => hrefs => pos

  45      var $multirefs = array();
  46      // toggle for auto-decoding element content

  47      var $decode_utf8 = true;
  48  
  49      /**

  50      * constructor that actually does the parsing

  51      *

  52      * @param    string $xml SOAP message

  53      * @param    string $encoding character encoding scheme of message

  54      * @param    string $method method for which XML is parsed (unused?)

  55      * @param    string $decode_utf8 whether to decode UTF-8 to ISO-8859-1

  56      * @access   public

  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          // Check whether content has been read.

  66          if(!empty($xml)){
  67              // Check XML encoding

  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                          // when HTTP says ISO-8859-1 (the default) and XML says UTF-8 (the typical), assume the other endpoint is just sloppy and proceed

  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              // Create an XML parser - why not xml_parser_create_ns?

  92              $this->parser = xml_parser_create($this->xml_encoding);
  93              // Set the options for parsing the XML data.

  94              //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);

  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              // Set the object for the parser.

  98              xml_set_object($this->parser, $this);
  99              // Set the element handlers for the parser.

 100              xml_set_element_handler($this->parser, 'start_element','end_element');
 101              xml_set_character_data_handler($this->parser,'character_data');
 102  
 103              // Parse the XML file.

 104              if(!xml_parse($this->parser,$xml,true)){
 105                  // Display an error message.

 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                  // get final value

 115                  $this->soapresponse = $this->message[$this->root_struct]['result'];
 116                  // get header value: no, because this is documented as XML string

 117  //                if($this->root_header != '' && isset($this->message[$this->root_header]['result'])){

 118  //                    $this->responseHeaders = $this->message[$this->root_header]['result'];

 119  //                }

 120                  // resolve hrefs/ids

 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      * 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  
 160          // else add self as child to whoever the current parent is

 161          if($pos != 0){
 162              $this->message[$this->parent]['children'] .= '|'.$pos;
 163          }
 164          // set my parent

 165          $this->message[$pos]['parent'] = $this->parent;
 166          // set self as current parent

 167          $this->parent = $pos;
 168          // set self as current value for this depth

 169          $this->depth_array[$this->depth] = $pos;
 170          // get element prefix

 171          if(strpos($name,':')){
 172              // get ns prefix

 173              $prefix = substr($name,0,strpos($name,':'));
 174              // get unqualified name

 175              $name = substr(strstr($name,':'),1);
 176          }
 177          // set status

 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          // set method

 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          // set my status

 195          $this->message[$pos]['status'] = $this->status;
 196          // set name

 197          $this->message[$pos]['name'] = htmlspecialchars($name);
 198          // set attrs

 199          $this->message[$pos]['attrs'] = $attrs;
 200  
 201          // loop through atts, logging ns and type declarations

 202          $attstr = '';
 203          foreach($attrs as $key => $value){
 204              $key_prefix = $this->getPrefix($key);
 205              $key_localpart = $this->getLocalPart($key);
 206              // if ns declarations, add to class level array of valid namespaces

 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                  // set method namespace

 215                  if($name == $this->root_struct_name){
 216                      $this->methodNamespace = $value;
 217                  }
 218              // if it's a type declaration, set type

 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                  // should do something here with the namespace of specified type?

 230              } elseif($key_localpart == 'arrayType'){
 231                  $this->message[$pos]['type'] = 'array';
 232                  /* do arrayType ereg here

 233                  [1]    arrayTypeValue    ::=    atype asize

 234                  [2]    atype    ::=    QName rank*

 235                  [3]    rank    ::=    '[' (',')* ']'

 236                  [4]    asize    ::=    '[' length~ ']'

 237                  [5]    length    ::=    nextDimension* Digit+

 238                  [6]    nextDimension    ::=    Digit+ ','

 239                  */
 240                  $expr = '([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]';
 241                  if(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              // specifies nil value (or not)

 254              } elseif ($key_localpart == 'nil'){
 255                  $this->message[$pos]['nil'] = ($value == 'true' || $value == '1');
 256              // some other attribute

 257              } elseif ($key != 'href' && $key != 'xmlns' && $key_localpart != 'encodingStyle' && $key_localpart != 'root') {
 258                  $this->message[$pos]['xattrs']['!' . $key] = $value;
 259              }
 260  
 261              if ($key == 'xmlns') {
 262                  $this->default_namespace = $value;
 263              }
 264              // log id

 265              if($key == 'id'){
 266                  $this->ids[$value] = $pos;
 267              }
 268              // root

 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              // for doclit

 276              $attstr .= " $key=\"$value\"";
 277          }
 278          // get namespace - must be done after namespace atts are processed

 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      * 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  
 305          // get element prefix

 306          if(strpos($name,':')){
 307              // get ns prefix

 308              $prefix = substr($name,0,strpos($name,':'));
 309              // get unqualified name

 310              $name = substr(strstr($name,':'),1);
 311          }
 312          
 313          // build to native type

 314          if(isset($this->body_position) && $pos > $this->body_position){
 315              // deal w/ multirefs

 316              if(isset($this->message[$pos]['attrs']['href'])){
 317                  // get id

 318                  $id = substr($this->message[$pos]['attrs']['href'],1);
 319                  // add placeholder to href array

 320                  $this->multirefs[$id][$pos] = 'placeholder';
 321                  // add set a reference to it as the result value

 322                  $this->message[$pos]['result'] =& $this->multirefs[$id][$pos];
 323              // build complexType values

 324              } elseif($this->message[$pos]['children'] != ''){
 325                  // if result has already been generated (struct/array)

 326                  if(!isset($this->message[$pos]['result'])){
 327                      $this->message[$pos]['result'] = $this->buildVal($pos);
 328                  }
 329              // build complexType values of attributes and possibly simpleContent

 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              // set value of simpleType (or nil complexType)

 347              } else {
 348                  //$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);

 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                  /* add value to parent's result, if parent is struct/array

 363                  $parent = $this->message[$pos]['parent'];

 364                  if($this->message[$parent]['type'] != 'map'){

 365                      if(strtolower($this->message[$parent]['type']) == 'array'){

 366                          $this->message[$parent]['result'][] = $this->message[$pos]['result'];

 367                      } else {

 368                          $this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result'];

 369                      }

 370                  }

 371                  */
 372              }
 373          }
 374          
 375          // for doclit

 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          // switch status

 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          // set parent back to my parent

 395          $this->parent = $this->message[$pos]['parent'];
 396      }
 397  
 398      /**

 399      * element content handler

 400      *

 401      * @param    resource $parser XML parser object

 402      * @param    string $data element content

 403      * @access   private

 404      */
 405  	function character_data($parser, $data){
 406          $pos = $this->depth_array[$this->depth];
 407          if ($this->xml_encoding=='UTF-8'){
 408              // TODO: add an option to disable this for folks who want

 409              // raw UTF-8 that, e.g., might not map to iso-8859-1

 410              // TODO: this can also be handled with xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");

 411              if($this->decode_utf8){
 412                  $data = utf8_decode($data);
 413              }
 414          }
 415          $this->message[$pos]['cdata'] .= $data;
 416          // for doclit

 417          if($this->status == 'header'){
 418              $this->responseHeaders .= $data;
 419          } else {
 420              $this->document .= $data;
 421          }
 422      }
 423  
 424      /**

 425      * get the parsed message

 426      *

 427      * @return    mixed

 428      * @access   public

 429      */
 430  	function get_response(){
 431          return $this->soapresponse;
 432      }
 433  
 434      /**

 435      * get the parsed headers

 436      *

 437      * @return    string XML or empty if no headers

 438      * @access   public

 439      */
 440  	function getHeaders(){
 441          return $this->responseHeaders;
 442      }
 443  
 444      /**

 445      * decodes simple types into PHP variables

 446      *

 447      * @param    string $value value to decode

 448      * @param    string $type XML type to decode

 449      * @param    string $typens XML type namespace to decode

 450      * @return    mixed PHP value

 451      * @access   private

 452      */
 453  	function decodeSimple($value, $type, $typens) {
 454          // TODO: use the namespace!

 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          // obscure numeric types

 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          // bogus: parser treats array with no elements as a simple type

 482          if ($type == 'array') {
 483              return array();
 484          }
 485          // everything else

 486          return (string) $value;
 487      }
 488  
 489      /**

 490      * builds response structures for compound values (arrays/structs)

 491      * and scalars

 492      *

 493      * @param    integer $pos position in node tree

 494      * @return    mixed    PHP value

 495      * @access   private

 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          // if there are children...

 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); // knock off empty

 507              // md array

 508              if(isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != ''){
 509                  $r=0; // rowcount

 510                  $c=0; // colcount

 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              // array

 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              // apache Map type: java hashtable

 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              // generic compound type

 534              //} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') {

 535              } else {
 536                  // Apache Vector type: treat as an array

 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                              // de-serialize repeated element name into an array

 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              // handle simpleContent

 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  ?>


Généré le : Mon Sep 10 13:53:24 2007 par Balluche grâce à PHPXref 0.7