[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/bundled-libs/XML/RPC/ -> Dump.php (source)

   1  <?php
   2  
   3  /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
   4  
   5  /**
   6   * Function and class to dump XML_RPC_Value objects in a nice way
   7   *
   8   * Should be helpful as a normal var_dump(..) displays all internals which
   9   * doesn't really give you an overview due to too much information.
  10   *
  11   * @category   Web Services
  12   * @package    XML_RPC
  13   * @author     Christian Weiske <cweiske@php.net>
  14   * @version    CVS: $Id: Dump.php,v 1.7 2005/01/24 03:47:55 danielc Exp $
  15   * @link       http://pear.php.net/package/XML_RPC
  16   */
  17  
  18  
  19  /**
  20   * Pull in the XML_RPC class
  21   */
  22  require_once 'XML/RPC.php';
  23  
  24  
  25  /**
  26   * Generates the dump of the XML_RPC_Value and echoes it
  27   *
  28   * @param object $value  the XML_RPC_Value object to dump
  29   *
  30   * @return void
  31   */
  32  function XML_RPC_Dump($value)
  33  {
  34      $dumper = new XML_RPC_Dump();
  35      echo $dumper->generateDump($value);
  36  }
  37  
  38  
  39  /**
  40   * Class which generates a dump of a XML_RPC_Value object
  41   *
  42   * @category   Web Services
  43   * @package    XML_RPC
  44   * @author     Christian Weiske <cweiske@php.net>
  45   * @version    Release: 1.4.0
  46   * @link       http://pear.php.net/package/XML_RPC
  47   */
  48  class XML_RPC_Dump
  49  {
  50      /**
  51       * The indentation array cache
  52       * @var array
  53       */
  54      var $arIndent      = array();
  55  
  56      /**
  57       * The spaces used for indenting the XML
  58       * @var string
  59       */
  60      var $strBaseIndent = '    ';
  61  
  62      /**
  63       * Returns the dump in XML format without printing it out
  64       *
  65       * @param object $value   the XML_RPC_Value object to dump
  66       * @param int    $nLevel  the level of indentation
  67       *
  68       * @return string  the dump
  69       */
  70      function generateDump($value, $nLevel = 0)
  71      {
  72          if (!is_object($value) && get_class($value) != 'xml_rpc_value') {
  73              require_once 'PEAR.php';
  74              PEAR::raiseError('Tried to dump non-XML_RPC_Value variable' . "\r\n",
  75                               0, PEAR_ERROR_PRINT);
  76              if (is_object($value)) {
  77                  $strType = get_class($value);
  78              } else {
  79                  $strType = gettype($value);
  80              }
  81              return $this->getIndent($nLevel) . 'NOT A XML_RPC_Value: '
  82                     . $strType . "\r\n";
  83          }
  84  
  85          switch ($value->kindOf()) {
  86          case 'struct':
  87              $ret = $this->genStruct($value, $nLevel);
  88              break;
  89          case 'array':
  90              $ret = $this->genArray($value, $nLevel);
  91              break;
  92          case 'scalar':
  93              $ret = $this->genScalar($value->scalarval(), $nLevel);
  94              break;
  95          default:
  96              require_once 'PEAR.php';
  97              PEAR::raiseError('Illegal type "' . $value->kindOf()
  98                               . '" in XML_RPC_Value' . "\r\n", 0,
  99                               PEAR_ERROR_PRINT);
 100          }
 101  
 102          return $ret;
 103      }
 104  
 105      /**
 106       * Returns the scalar value dump
 107       *
 108       * @param object $value   the scalar XML_RPC_Value object to dump
 109       * @param int    $nLevel  the level of indentation
 110       *
 111       * @return string  Dumped version of the scalar value
 112       */
 113      function genScalar($value, $nLevel)
 114      {
 115          if (gettype($value) == 'object') {
 116              $strClass = ' ' . get_class($value);
 117          } else {
 118              $strClass = '';
 119          }
 120          return $this->getIndent($nLevel) . gettype($value) . $strClass
 121                 . ' ' . $value . "\r\n";
 122      }
 123  
 124      /**
 125       * Returns the dump of a struct
 126       *
 127       * @param object $value   the struct XML_RPC_Value object to dump
 128       * @param int    $nLevel  the level of indentation
 129       *
 130       * @return string  Dumped version of the scalar value
 131       */
 132      function genStruct($value, $nLevel)
 133      {
 134          $value->structreset();
 135          $strOutput = $this->getIndent($nLevel) . 'struct' . "\r\n";
 136          while (list($key, $keyval) = $value->structeach()) {
 137              $strOutput .= $this->getIndent($nLevel + 1) . $key . "\r\n";
 138              $strOutput .= $this->generateDump($keyval, $nLevel + 2);
 139          }
 140          return $strOutput;
 141      }
 142  
 143      /**
 144       * Returns the dump of an array
 145       *
 146       * @param object $value   the array XML_RPC_Value object to dump
 147       * @param int    $nLevel  the level of indentation
 148       *
 149       * @return string  Dumped version of the scalar value
 150       */
 151      function genArray($value, $nLevel)
 152      {
 153          $nSize     = $value->arraysize();
 154          $strOutput = $this->getIndent($nLevel) . 'array' . "\r\n";
 155          for($nA = 0; $nA < $nSize; $nA++) {
 156              $strOutput .= $this->getIndent($nLevel + 1) . $nA . "\r\n";
 157              $strOutput .= $this->generateDump($value->arraymem($nA),
 158                                                $nLevel + 2);
 159          }
 160          return $strOutput;
 161      }
 162  
 163      /**
 164       * Returns the indent for a specific level and caches it for faster use
 165       *
 166       * @param int $nLevel  the level
 167       *
 168       * @return string  the indented string
 169       */
 170      function getIndent($nLevel)
 171      {
 172          if (!isset($this->arIndent[$nLevel])) {
 173              $this->arIndent[$nLevel] = str_repeat($this->strBaseIndent, $nLevel);
 174          }
 175          return $this->arIndent[$nLevel];
 176      }
 177  }
 178  
 179  /*
 180   * Local variables:
 181   * tab-width: 4
 182   * c-basic-offset: 4
 183   * c-hanging-comment-ender-p: nil
 184   * End:
 185   */
 186  
 187  ?>


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics