XML_RPC
[ class tree: XML_RPC ] [ index: XML_RPC ] [ all elements ]

Source for file Dump.php

Documentation is available at Dump.php

  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 178076 2005-01-24 03:47:55Z danielc $
  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.5.2
  46.  * @link       http://pear.php.net/package/XML_RPC
  47.  */
  48. {
  49.     /**
  50.      * The indentation array cache
  51.      * @var array 
  52.      */
  53.     var $arIndent      = array();
  54.  
  55.     /**
  56.      * The spaces used for indenting the XML
  57.      * @var string 
  58.      */
  59.     var $strBaseIndent = '    ';
  60.  
  61.     /**
  62.      * Returns the dump in XML format without printing it out
  63.      *
  64.      * @param object $value   the XML_RPC_Value object to dump
  65.      * @param int    $nLevel  the level of indentation
  66.      *
  67.      * @return string  the dump
  68.      */
  69.     function generateDump($value$nLevel = 0)
  70.     {
  71.         if (!is_object($value&& get_class($value!= 'xml_rpc_value'{
  72.             require_once 'PEAR.php';
  73.             PEAR::raiseError('Tried to dump non-XML_RPC_Value variable' "\r\n",
  74.                              0PEAR_ERROR_PRINT);
  75.             if (is_object($value)) {
  76.                 $strType get_class($value);
  77.             else {
  78.                 $strType gettype($value);
  79.             }
  80.             return $this->getIndent($nLevel'NOT A XML_RPC_Value: '
  81.                    . $strType "\r\n";
  82.         }
  83.  
  84.         switch ($value->kindOf()) {
  85.         case 'struct':
  86.             $ret $this->genStruct($value$nLevel);
  87.             break;
  88.         case 'array':
  89.             $ret $this->genArray($value$nLevel);
  90.             break;
  91.         case 'scalar':
  92.             $ret $this->genScalar($value->scalarval()$nLevel);
  93.             break;
  94.         default:
  95.             require_once 'PEAR.php';
  96.             PEAR::raiseError('Illegal type "' $value->kindOf()
  97.                              . '" in XML_RPC_Value' "\r\n"0,
  98.                              PEAR_ERROR_PRINT);
  99.         }
  100.  
  101.         return $ret;
  102.     }
  103.  
  104.     /**
  105.      * Returns the scalar value dump
  106.      *
  107.      * @param object $value   the scalar XML_RPC_Value object to dump
  108.      * @param int    $nLevel  the level of indentation
  109.      *
  110.      * @return string  Dumped version of the scalar value
  111.      */
  112.     function genScalar($value$nLevel)
  113.     {
  114.         if (gettype($value== 'object'{
  115.             $strClass ' ' get_class($value);
  116.         else {
  117.             $strClass '';
  118.         }
  119.         return $this->getIndent($nLevelgettype($value$strClass
  120.                . ' ' $value "\r\n";
  121.     }
  122.  
  123.     /**
  124.      * Returns the dump of a struct
  125.      *
  126.      * @param object $value   the struct XML_RPC_Value object to dump
  127.      * @param int    $nLevel  the level of indentation
  128.      *
  129.      * @return string  Dumped version of the scalar value
  130.      */
  131.     function genStruct($value$nLevel)
  132.     {
  133.         $value->structreset();
  134.         $strOutput $this->getIndent($nLevel'struct' "\r\n";
  135.         while (list($key$keyval$value->structeach()) {
  136.             $strOutput .= $this->getIndent($nLevel + 1$key "\r\n";
  137.             $strOutput .= $this->generateDump($keyval$nLevel + 2);
  138.         }
  139.         return $strOutput;
  140.     }
  141.  
  142.     /**
  143.      * Returns the dump of an array
  144.      *
  145.      * @param object $value   the array XML_RPC_Value object to dump
  146.      * @param int    $nLevel  the level of indentation
  147.      *
  148.      * @return string  Dumped version of the scalar value
  149.      */
  150.     function genArray($value$nLevel)
  151.     {
  152.         $nSize     $value->arraysize();
  153.         $strOutput $this->getIndent($nLevel'array' "\r\n";
  154.         for($nA = 0; $nA $nSize$nA++{
  155.             $strOutput .= $this->getIndent($nLevel + 1$nA "\r\n";
  156.             $strOutput .= $this->generateDump($value->arraymem($nA),
  157.                                               $nLevel + 2);
  158.         }
  159.         return $strOutput;
  160.     }
  161.  
  162.     /**
  163.      * Returns the indent for a specific level and caches it for faster use
  164.      *
  165.      * @param int $nLevel  the level
  166.      *
  167.      * @return string  the indented string
  168.      */
  169.     function getIndent($nLevel)
  170.     {
  171.         if (!isset($this->arIndent[$nLevel])) {
  172.             $this->arIndent[$nLevelstr_repeat($this->strBaseIndent$nLevel);
  173.         }
  174.         return $this->arIndent[$nLevel];
  175.     }
  176. }
  177.  
  178. /*
  179.  * Local variables:
  180.  * tab-width: 4
  181.  * c-basic-offset: 4
  182.  * c-hanging-comment-ender-p: nil
  183.  * End:
  184.  */
  185.  
  186. ?>

Documentation generated on Tue, 18 Aug 2009 17:30:02 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.