[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/includes/domit/ -> dom_xmlrpc_array_parser.php (source)

   1  <?php
   2  /**

   3  * dom_xmlrpc_array_parser handles SAX events to convert a DOM XML-RPC XML string into a PHP array

   4  * @package dom-xmlrpc

   5  * @copyright (C) 2004 John Heinstein. All rights reserved

   6  * @license http://www.gnu.org/copyleft/lesser.html LGPL License

   7  * @author John Heinstein <johnkarl@nbnet.nb.ca>

   8  * @link http://www.engageinteractive.com/dom_xmlrpc/ DOM XML-RPC Home Page

   9  * DOM XML-RPC is Free Software

  10  **/
  11  
  12  if (!defined('DOM_XMLRPC_INCLUDE_PATH')) {
  13      define('DOM_XMLRPC_INCLUDE_PATH', (dirname(__FILE__) . "/"));
  14  }
  15  
  16  require_once (DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_parser.php');
  17  
  18  /**

  19  * Handles SAX events to convert a DOM XML-RPC XML string into a PHP array

  20  *

  21  * @package dom-xmlrpc

  22  * @author John Heinstein <johnkarl@nbnet.nb.ca>

  23  */
  24  class dom_xmlrpc_array_parser extends dom_xmlrpc_parser {
  25  
  26      /**

  27      * Handles start element events

  28      * @param object A reference to the SAX parser

  29      * @param string The name of the start element tag

  30      * @param array An array of attributes (never used by XML-RPC spec)

  31      */
  32  	function startElement($parser, $name, $attrs) {
  33          switch($name) {
  34              case DOM_XMLRPC_TYPE_METHODCALL:
  35              case DOM_XMLRPC_TYPE_METHODRESPONSE:
  36              case DOM_XMLRPC_TYPE_FAULT:
  37                  $this->arrayDocument->methodType = $name; //register methodType

  38                  break;
  39              case DOM_XMLRPC_TYPE_ARRAY:
  40              case DOM_XMLRPC_TYPE_STRUCT:
  41                  $this->lastArrayType[] = $name;
  42                  $this->lastArray[] = array();
  43                  break;
  44          }
  45      } //startElement

  46  
  47      /**

  48      * Handles end element events

  49      * @param object A reference to the SAX parser

  50      * @param string The name of the end element tag

  51      */
  52  	function endElement($parser, $name) {
  53          switch($name) {
  54              case DOM_XMLRPC_TYPE_STRING:
  55                  //$this->addValue(html_entity_decode($this->charContainer, ENT_QUOTES));

  56                  $this->addValue($this->charContainer);
  57                  break;
  58              case DOM_XMLRPC_TYPE_I4:
  59              case DOM_XMLRPC_TYPE_INT:
  60                  $this->addValue((int)($this->charContainer));
  61                  break;
  62              case DOM_XMLRPC_TYPE_DOUBLE:
  63                  $this->addValue(floatval($this->charContainer));
  64                  break;
  65              case DOM_XMLRPC_TYPE_BOOLEAN:
  66                  $this->addValue((bool)(trim($this->charContainer)));
  67                  break;
  68              case DOM_XMLRPC_TYPE_BASE64:
  69                  require_once (DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_base64.php');
  70                  $base64 = new dom_xmlrpc_base64();
  71                  $base64->fromString($this->charContainer);
  72                  $this->addValue($base64); //should I add object or string?

  73                  break;
  74              case DOM_XMLRPC_TYPE_DATETIME:
  75                  require_once (DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_datetime_iso8601.php');
  76                  $dateTime = new dom_xmlrpc_datetime_iso8601($this->charContainer);
  77                  $this->addValue($dateTime); //should I add object or string?

  78                  break;
  79              case DOM_XMLRPC_TYPE_VALUE:
  80                  //if charContainer has anything in it,

  81                  //then there mustn't be a subnode, therefore a <string>

  82                  $myValue = trim($this->charContainer);
  83                  //if ($myValue != '') $this->addValue(html_entity_decode($myValue, ENT_QUOTES));

  84                  if ($myValue != '') $this->addValue($myValue);
  85                  break;
  86              case DOM_XMLRPC_TYPE_ARRAY:
  87              case DOM_XMLRPC_TYPE_STRUCT:
  88                  $value =& array_pop($this->lastArray);
  89                  $this->addValue($value);
  90                  array_pop($this->lastArrayType);
  91                  break;
  92              case DOM_XMLRPC_TYPE_MEMBER:
  93                  array_pop($this->lastStructName);
  94                  break;
  95              case DOM_XMLRPC_TYPE_NAME:
  96                  $this->lastStructName[] = trim($this->charContainer);
  97                  $this->charContainer = '';
  98                  break;
  99              case DOM_XMLRPC_TYPE_METHODNAME:
 100                  $this->arrayDocument->methodName = trim($this->charContainer);
 101                  $this->charContainer = '';
 102                  break;
 103          }
 104      }    //endElement

 105  
 106      /**

 107      * Adds an XML-RPC value to the results array

 108      * @param mixed The value

 109      */
 110  	function addValue($value) {
 111          $upper = count($this->lastArray) - 1;
 112  
 113          if ($upper > -1) {
 114              if ($this->lastArrayType[$upper] == DOM_XMLRPC_TYPE_STRUCT) {
 115                  $currentName = $this->lastStructName[(count($this->lastStructName) - 1)];
 116  
 117                  switch ($currentName) {
 118                      case DOM_XMLRPC_NODEVALUE_FAULTCODE:
 119                          $this->arrayDocument->faultCode = $value;
 120                          break;
 121  
 122                      case DOM_XMLRPC_NODEVALUE_FAULTSTRING:
 123                          $this->arrayDocument->faultString = $value;
 124                          break;
 125  
 126                      default:
 127                          //associative array item

 128                          $this->lastArray[$upper][$currentName] = $value;
 129                          break;
 130                  }
 131              }
 132              else {
 133                  //indexed array item

 134                  $this->lastArray[$upper][] = $value;
 135              }
 136          }
 137          else {
 138              array_push($this->arrayDocument->params, $value);
 139          }
 140  
 141          $this->charContainer = '';
 142      } //addValue

 143  } //dom_xmlrpc_array_parser

 144  
 145  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics