home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / Var_Dump.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  36.5 KB  |  998 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group             |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Frederic Poeydomenge <frederic.poeydomenge@free.fr>         |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id$
  20.  
  21. require_once 'PEAR.php';
  22.  
  23. // +----------------------------------------------------------------------+
  24. // | SYNOPSIS                                                             |
  25. // +----------------------------------------------------------------------+
  26. // |   Var_Dump::display($vars);                                          |
  27. // | or                                                                   |
  28. // |   Var_Dump::display($vars,'',VAR_DUMP_DISPLAY_MODE_HTML_TABLE);      |
  29. // | or                                                                   |
  30. // |   $text = Var_Dump::r_display($vars);                                |
  31. // | or                                                                   |
  32. // |   $text = Var_Dump::r_display($vars,'',VAR_DUMP_DISPLAY_MODE_TEXT);  |
  33. // | or                                                                   |
  34. // |   $foo=new Var_Dump($confVD);                                        |
  35. // |   $foo->setDisplayMode($confDM);                                     |
  36. // |   $foo->display($vars);                                              |
  37. // +----------------------------------------------------------------------+
  38.  
  39. if (!defined('VAR_DUMP_CONSTANTS')) {
  40.  
  41.     define('VAR_DUMP_MAGIC', 'fce75110d95bedd51264ce2a99cfc908');
  42.     
  43.     define('VAR_DUMP_ARRAY_TYPE',              1);
  44.     define('VAR_DUMP_ARRAY_VALUE',             2);
  45.     define('VAR_DUMP_ARRAY_MAGIC',             0);
  46.  
  47.     define('VAR_DUMP_DISPLAY_MODE_TEXT',       1);
  48.     define('VAR_DUMP_DISPLAY_MODE_HTML_TEXT',  2);
  49.     define('VAR_DUMP_DISPLAY_MODE_HTML_TABLE', 3);
  50.  
  51.     define('VAR_DUMP_CONSTANTS',            true);
  52.  
  53.     // 2003-08-20 Walt Boring <waboring at 3gstech dot com> : feature which
  54.     // allows to turn off a few output options for dumping an object
  55.     define('VAR_DUMP_NO_CLASS_VARS', 1);
  56.     define('VAR_DUMP_NO_CLASS_METHODS', 2);
  57.     //turns both class vars and class methods off
  58.     define('VAR_DUMP_NO_CLASS_INFO', 3);
  59.  
  60.  
  61. }
  62.  
  63. /**
  64. * Displays informations about the values of variables on a graphical way
  65. * - If given a simple variable (string, integer, double, ressource), the
  66. * value itself is printed.
  67. * - If given an array, it is explored recursively and values are presented
  68. * in a format that shows keys and elements.
  69. * - If given an object, informations about the object and the class
  70. * are printed.
  71. */
  72. class Var_Dump extends PEAR
  73. {
  74.         
  75.     /**
  76.     * Selected language for error messages
  77.     * @var string $lang
  78.     */
  79.     var $lang = 'en';
  80.  
  81.     /**
  82.     * Messages in various languages
  83.     * @var string $messages
  84.     */
  85.     var $messages;
  86.  
  87.     /**
  88.     * @var array $_VarDumpArray An array representing the structure of submitted variables
  89.     */
  90.     var $_VarDumpArray = array();
  91.  
  92.     /**
  93.     * @var array $_VarDumpConfGlobal Global parameters for an instance of the class
  94.     *                'showNotParsed' => Tell if we show 'not parsed' variables or not
  95.     *                'displayMode'   => Default display mode : Text or Html
  96.     *                'displaySkin'   => Default skin name
  97.     */
  98.     var $_VarDumpConfGlobal = array();
  99.  
  100.     /**
  101.     * @var array $_VarDumpConfVisual Visual parameters for the rendering
  102.     *                'bordercolor'   => border color
  103.     *                'color1'        => cells color for odd rows
  104.     *                'color2'        => cells color for even rows
  105.     *                'bordersize'    => border size
  106.     *                'cellpadding'   => padding of the table
  107.     *                'cellspacing'   => spacing of the table
  108.     *                'fontface'      => font face
  109.     *                'fontsize'      => font size
  110.     *                'fontcolor1'    => font color for odd rows
  111.     *                'fontcolor2'    => font color for even rows
  112.     */
  113.     var $_VarDumpConfVisual = array();
  114.  
  115.     /**
  116.     * @var string $_VarDumpDisplayFont1Start Text : Starting tag <font...> or empty
  117.     * @var string $_VarDumpDisplayFont1End   Text : Ending tag </font> or empty
  118.     * @var string $_VarDumpDisplayFont2Start Value : Starting tag <font...> or empty
  119.     * @var string $_VarDumpDisplayFont2End   Value : Ending tag </font> or empty
  120.     */
  121.     var $_VarDumpDisplayFont1Start = '';
  122.     var $_VarDumpDisplayFont1End   = '';
  123.     var $_VarDumpDisplayFont2Start = '';
  124.     var $_VarDumpDisplayFont2End   = '';
  125.  
  126.  
  127.     // {{{ Var_Dump()
  128.     /**
  129.     * Var_Dump() - Constructor
  130.     *
  131.     * If an instance of the class is created, initialize the global parameters for this
  132.     * instance : if we show 'not parsed' variables or not, the default display mode,
  133.     * the default skin name..
  134.     *
  135.     * @param array $conf Global parameters for an instance of the class
  136.     *                'showNotParsed' => Tell if we show 'not parsed' variables or not
  137.     *                'displayMode'   => Default display mode : Text or Html
  138.     *                'displaySkin'   => Default skin name
  139.     */
  140.     function Var_Dump($conf = array())
  141.     {
  142.         $conf2=array_merge(
  143.             array(
  144.                 'language'      => 'en',
  145.                 'showNotParsed' => true,
  146.                 'displayMode'   => VAR_DUMP_DISPLAY_MODE_HTML_TEXT,
  147.                 'displaySkin'   => ''
  148.             ),
  149.             $conf
  150.         );
  151.         $this->_VarDumpConfGlobal = $conf2;
  152.         $this->lang = $conf2['language'];
  153.         $this->setSkin(
  154.             $conf2['displayMode'],
  155.             $conf2['displaySkin']
  156.         );
  157.  
  158.         $this->messages = array(
  159.             'TYPE_ARRAY' => array(
  160.                 'en' => 'Array',
  161.                 'fr' => 'Tableau'
  162.             ),
  163.             'TYPE_LONG' => array(
  164.                 'en' => 'Long',
  165.                 'fr' => 'Long'
  166.             ),
  167.             'TYPE_INT' => array(
  168.                 'en' => 'Int',
  169.                 'fr' => 'Entier'
  170.             ),
  171.             'TYPE_INTEGER' => array(
  172.                 'en' => 'Integer',
  173.                 'fr' => 'Entier'
  174.             ),
  175.             'TYPE_DOUBLE' => array(
  176.                 'en' => 'Double',
  177.                 'fr' => 'Double'
  178.             ),
  179.             'TYPE_FLOAT' => array(
  180.                 'en' => 'Float',
  181.                 'fr' => 'Flottant'
  182.             ),
  183.             'TYPE_REAL' => array(
  184.                 'en' => 'Real',
  185.                 'fr' => 'RΘel'
  186.             ),
  187.             'TYPE_STRING' => array(
  188.                 'en' => 'String',
  189.                 'fr' => 'Chaine'
  190.             ),
  191.             'TYPE_BOOLEAN' => array(
  192.                 'en' => 'Boolean',
  193.                 'fr' => 'BoolΘen'
  194.             ),
  195.             'TYPE_NUMERIC' => array(
  196.                 'en' => 'Numeric',
  197.                 'fr' => 'NumΘrique'
  198.             ),
  199.             'TYPE_RESOURCE' => array(
  200.                 'en' => 'Resource',
  201.                 'fr' => 'Ressource'
  202.             ),
  203.             'TYPE_SCALAR' => array(
  204.                 'en' => 'Scalar',
  205.                 'fr' => 'Scalaire'
  206.             ),
  207.             'TYPE_NULL' => array(
  208.                 'en' => 'Null',
  209.                 'fr' => 'Null'
  210.             ),
  211.             'TYPE_UNKNOWN' => array(
  212.                 'en' => 'Unknown type',
  213.                 'fr' => 'Type inconnu'
  214.             ),
  215.             'BOOLEAN_TRUE' => array(
  216.                 'en' => 'TRUE',
  217.                 'fr' => 'VRAI'
  218.             ),
  219.             'BOOLEAN_FALSE' => array(
  220.                 'en' => 'FALSE',
  221.                 'fr' => 'FAUX'
  222.             ),
  223.             'OBJECT_CLASS_NAME' => array(
  224.                 'en' => 'Class name',
  225.                 'fr' => 'Nom de la classe'
  226.             ),
  227.             'OBJECT_PARENT' => array(
  228.                 'en' => 'Parent class',
  229.                 'fr' => 'Classe parente'
  230.             ),
  231.             'OBJECT_CLASS_VARS' => array(
  232.                 'en' => 'Class vars',
  233.                 'fr' => 'Variables de la classe'
  234.             ),
  235.             'OBJECT_CLASS_METHODS' => array(
  236.                 'en' => 'Class methods',
  237.                 'fr' => 'MΘthodes de la classe'
  238.             ),
  239.             'OBJECT_OBJECT_VARS' => array(
  240.                 'en' => 'Object vars',
  241.                 'fr' => 'Variables d\'instance'
  242.             ),
  243.             'EMPTY_ARRAY' => array(
  244.                 'en' => 'Empty array',
  245.                 'fr' => 'Tableau vide'
  246.             ),
  247.             'NOT_PARSED' => array(
  248.                 'en' => 'Not parsed',
  249.                 'fr' => 'Non analysΘ'
  250.             ),
  251.             'NON_EXISTENT' => array(
  252.                 'en' => 'Non-existent variable',
  253.                 'fr' => 'Variable inexistente'
  254.             )
  255.         );
  256.  
  257.     }
  258.     // }}}
  259.  
  260.  
  261.     // {{{ display()
  262.     /**
  263.     * display() - Displays informations about a variable
  264.     *
  265.     * This method displays informations about the values of a variable on a
  266.     * graphical way, arrays and objects being explored recursively
  267.     *
  268.     * @param $variable      A variable to explore
  269.     * @param string $except If not empty, name of the key not to
  270.     *                       explore, to avoid parsing references to itself
  271.     */
  272.     function display($variable = '', $except = '', $displayMode = false, $options=0)
  273.     {
  274.         if (!isset($this) or get_class($this) != 'var_dump') {
  275.             $this = & new Var_Dump;
  276.             if ($displayMode !== false) {
  277.                 $this->_VarDumpConfGlobal['displayMode'] = $displayMode;
  278.                 $this->setSkin($displayMode);
  279.             }
  280.         }
  281.  
  282.         echo $this->r_display($variable, $except, $displayMode, $options);
  283.     }
  284.     // }}}
  285.  
  286.  
  287.     // {{{ r_display()
  288.     /**
  289.     * r_display() - Returns informations about a variable, ready to be printed
  290.     *
  291.     * This method returns informations about the values of a variable, ready
  292.     * to be printed on a graphical way, arrays and objects being explored
  293.     * recursively
  294.     *
  295.     * @param $variable      A variable to explore
  296.     * @param string $except If not empty, name of the key not to
  297.     *                       explore, to avoid parsing references to itself
  298.     */
  299.     function r_display($variable = '', $except = '', $displayMode = false, $options=0)
  300.     {
  301.         if (!isset($this) or get_class($this) != 'var_dump') {
  302.             $this = & new Var_Dump;
  303.             if ($displayMode !== false) {
  304.                 $this->_VarDumpConfGlobal['displayMode'] = $displayMode;
  305.                 $this->setSkin($displayMode);
  306.             }
  307.         }
  308.  
  309.         $this->_VarDumpConfGlobal['displayOptions'] = $options;
  310.  
  311.         $this->_populate($variable, $except);
  312.  
  313.         $this->_generateFontTags();
  314.  
  315.         switch($this->_VarDumpConfGlobal['displayMode']) {
  316.  
  317.             case VAR_DUMP_DISPLAY_MODE_TEXT:
  318.                 return $this->_formatTableTEXT($this->_VarDumpArray[0],false);
  319.                 break;
  320.             
  321.             case VAR_DUMP_DISPLAY_MODE_HTML_TEXT:
  322.                 return $this->_formatTableTEXT($this->_VarDumpArray[0],true);
  323.                 break;
  324.                 
  325.             case VAR_DUMP_DISPLAY_MODE_HTML_TABLE:
  326.             default:
  327.                 return $this->_formatTableHTML($this->_VarDumpArray);
  328.                 break;
  329.                 
  330.         }
  331.     }
  332.     // }}}
  333.             
  334.  
  335.     // {{{ _populate()
  336.     /**
  337.     * _populate() - Fills the informations concerning a single variable
  338.     *
  339.     * This method fills the local array $this->_VarDumpArray with the
  340.     * informations concerning a single variable
  341.     * When parsing $GLOBALS variable, avoid parsing recursively the
  342.     * reference to itself.
  343.     *
  344.     * @param $variable      The variable to explore
  345.     * @param string $except If not empty, name of the key not to
  346.     *                       explore, to avoid parsing references to itself
  347.     */
  348.     function _populate($variable, $except = '')
  349.     {
  350.         $lang=$this->lang;
  351.         $this->_VarDumpArray=array();
  352.         if (empty($except)) {
  353.             $w_except = '';
  354.         } else {
  355.             $w_except = ' '.trim($except);
  356.         }
  357.         if (//$variable == $GLOBALS does not work
  358.             is_array($variable) and
  359.             isset($variable['_GET']) and
  360.             isset($variable['_POST']) and
  361.             isset($variable['_COOKIE']) and
  362.             isset($variable['_SERVER']) and
  363.             isset($variable['_ENV'])
  364.         ) {
  365.             $this->_VarDumpArray[] = $this->_parseArray($GLOBALS, 'GLOBALS'.$w_except);
  366.         } else {
  367.             if (isset($variable)) {
  368.                 if (is_array($variable)) {
  369.                     $this->_VarDumpArray[] = $this->_parseArray($variable, $except);
  370.                 } else if (is_object($variable)) {
  371.                     $this->_VarDumpArray[] = $this->_parseObject($variable);
  372.                 } else {
  373.                     $this->_VarDumpArray[] = $this->_parseVariable($variable);
  374.                 }
  375.             } else {
  376.                 $this->_VarDumpArray[] =
  377.                     array(
  378.                         VAR_DUMP_ARRAY_MAGIC => VAR_DUMP_MAGIC,
  379.                         VAR_DUMP_ARRAY_TYPE  => $this->messages['TYPE_NULL'][$lang],
  380.                         VAR_DUMP_ARRAY_VALUE => $this->messages['NON_EXISTENT'][$lang]
  381.                     );
  382.             }
  383.         }
  384.     }
  385.     // }}}
  386.  
  387.  
  388.     // {{{ _parseVariable()
  389.     /**
  390.     * _parseVariable() - Parse (recursively) a variable
  391.     *
  392.     * This method parse a variable, either returning informations about
  393.     * this variable, or in the case of an object or array, returning
  394.     * recursive informations about this variable.
  395.     *
  396.     * @param $variable A variable to explore
  397.     */
  398.     function _parseVariable($variable)
  399.     {
  400.         $lang=$this->lang;
  401.         if (is_object($variable)) {
  402.             return $this->_parseObject($variable);
  403.         } elseif (is_array($variable)) {
  404.             return $this->_parseArray($variable);
  405.         } elseif (is_long($variable)) {
  406.             $type = $this->messages['TYPE_LONG'][$lang];
  407.         } elseif (is_int($variable)) {
  408.             $type = $this->messages['TYPE_INT'][$lang];
  409.         } elseif (is_integer($variable)) {
  410.             $type = $this->messages['TYPE_INTEGER'][$lang];
  411.         } elseif (is_double($variable)) {
  412.             $type = $this->messages['TYPE_DOUBLE'][$lang];
  413.         } elseif (is_float($variable)) {
  414.             $type = $this->messages['TYPE_FLOAT'][$lang];
  415.         } elseif (is_real($variable)) {
  416.             $type = $this->messages['TYPE_REAL'][$lang];
  417.         } elseif (is_string($variable)) {
  418.             $type = $this->messages['TYPE_STRING'][$lang].'['.strlen($variable).']';
  419.         } elseif (is_bool($variable)) {
  420.             $type = $this->messages['TYPE_BOOLEAN'][$lang];
  421.             if ($variable==true) {
  422.                 $variable = $this->messages['BOOLEAN_TRUE'][$lang];
  423.             } else {
  424.                 $variable = $this->messages['BOOLEAN_FALSE'][$lang];
  425.             }
  426.         } elseif (is_numeric($variable)) {
  427.             $type = $this->messages['TYPE_NUMERIC'][$lang];
  428.         } elseif (is_resource($variable)) {
  429.             $type = $this->messages['TYPE_RESOURCE'][$lang].'['.get_resource_type($variable).']';
  430.         } elseif (is_scalar($variable)) {
  431.             $type = $this->messages['TYPE_SCALAR'][$lang];
  432.         } elseif (is_null($variable)) {
  433.             $type = $this->messages['TYPE_NULL'][$lang];
  434.             $variable = 'Null';
  435.         } else {
  436.             $type = $this->messages['TYPE_UNKNOWN'][$lang].'['.gettype($variable).']';
  437.         }
  438.         return
  439.             array(
  440.                 VAR_DUMP_ARRAY_MAGIC => VAR_DUMP_MAGIC,
  441.                 VAR_DUMP_ARRAY_TYPE  => $type,
  442.                 VAR_DUMP_ARRAY_VALUE => $variable
  443.             );
  444.     }
  445.     // }}}
  446.  
  447.  
  448.     // {{{ _parseArray()
  449.     /**
  450.     * _parseArray() - Parse recursively an array
  451.     *
  452.     * This method returns recursive informations on an array :
  453.     * structure, keys and values
  454.     *
  455.     * @param array  $array  An array to explore
  456.     * @param string $except If not empty, name of the key not to
  457.     *                       explore, to avoid parsing references to itself
  458.     */
  459.     function _parseArray($array, $except = '')
  460.     {
  461.         $lang=$this->lang;
  462.         if (is_string($except)) {
  463.             $except_array = explode(' ',$except);
  464.         } else {
  465.             $except_array = array();
  466.         }
  467.         
  468.         if (!is_array($array)) {    
  469.             return $this->_parseVariable($array);
  470.         } else {
  471.             if (count($array)==0) {
  472.                 return 
  473.                     array(
  474.                         VAR_DUMP_ARRAY_MAGIC => VAR_DUMP_MAGIC,
  475.                         VAR_DUMP_ARRAY_TYPE  => $this->messages['EMPTY_ARRAY'][$lang],
  476.                         VAR_DUMP_ARRAY_VALUE => ''
  477.                     );
  478.             } else {
  479.                 $localArray = array();
  480.                 foreach($array as $key => $value) {
  481.                     if (! (in_array($key, $except_array, TRUE))) {
  482.                         $localArray[$key] = $this->_parseArray($value, $except);
  483.                     } else {
  484.                         $localArray[$key] = array(
  485.                             VAR_DUMP_ARRAY_MAGIC => VAR_DUMP_MAGIC,
  486.                             VAR_DUMP_ARRAY_TYPE  => $this->messages['NOT_PARSED'][$lang],
  487.                             VAR_DUMP_ARRAY_VALUE => ''
  488.                         );
  489.                     }
  490.                 }
  491.                 return $localArray;
  492.             }
  493.         }
  494.     }
  495.     // }}}
  496.  
  497.  
  498.     // {{{ _parseObject()
  499.     /**
  500.     * _parseObject() - Returns informations on an object
  501.     *
  502.     * This method returns informations on an object and its class :
  503.     * default class variables and methods, current object state
  504.     *
  505.     * @param object $object An object to explore
  506.     */
  507.     function _parseObject($object)
  508.     {
  509.         $lang=$this->lang;
  510.         if (!is_object($object)) {    
  511.             return $this->_parseVariable($object);
  512.         } else {
  513.             $className=get_class($object);
  514.             $arr = array(
  515.                 $this->messages['OBJECT_CLASS_NAME'][$lang]    => $this->_parseVariable($className),
  516.                 $this->messages['OBJECT_PARENT'][$lang]        => $this->_parseVariable(get_parent_class($object)),
  517.                 $this->messages['OBJECT_CLASS_VARS'][$lang]    => $this->_parseArray(get_class_vars($className)),
  518.                 $this->messages['OBJECT_CLASS_METHODS'][$lang] => $this->_parseArray(get_class_methods($className)),                
  519.                 $this->messages['OBJECT_OBJECT_VARS'][$lang]   => $this->_parseArray(get_object_vars($object))
  520.             );
  521.  
  522.             switch ($this->_VarDumpConfGlobal['displayOptions'] & VAR_DUMP_NO_CLASS_INFO) {            
  523.             case VAR_DUMP_NO_CLASS_VARS:                
  524.                 unset($arr[$this->messages['OBJECT_CLASS_VARS'][$lang]]);
  525.                 break;
  526.             case VAR_DUMP_NO_CLASS_METHODS:
  527.                 unset($arr[$this->messages['OBJECT_CLASS_METHODS'][$lang]]);
  528.                 break;
  529.             case VAR_DUMP_NO_CLASS_INFO:
  530.                 unset($arr[$this->messages['OBJECT_CLASS_VARS'][$lang]]);
  531.                 unset($arr[$this->messages['OBJECT_CLASS_METHODS'][$lang]]);
  532.                 break;
  533.             default:
  534.                 break;
  535.             }
  536.             return $arr;
  537.         }
  538.     }
  539.     // }}}
  540.  
  541.  
  542.     // {{{ _isSingleVariable()
  543.     /**
  544.     * _isSingleVariable() - Tells if a variable is a single variable
  545.     *
  546.     * This method tells if a variable is a single variable (long,
  547.     * string, double...) or a more complex one (array, object...)
  548.     *
  549.     * @param $variable The variable to check
  550.     * @return          True if it's a single variable
  551.     *                  False if it's a more complex variable
  552.     */
  553.     function _isSingleVariable($variable)
  554.     {
  555.         return (
  556.             is_array($variable) and
  557.             isset($variable[VAR_DUMP_ARRAY_MAGIC]) and
  558.             $variable[VAR_DUMP_ARRAY_MAGIC]==VAR_DUMP_MAGIC
  559.         );
  560.     }
  561.     // }}}
  562.  
  563.  
  564.     // {{{ _generateFontTags()
  565.     /**
  566.     * _generateFontTags() - Generates the font tags <font...>
  567.     *
  568.     * This method generates the font tags <font...> with the
  569.     * font size, color and face values choosen. If none of the
  570.     * font parameters was modified, use the default font.
  571.     */
  572.     function _generateFontTags()
  573.     {
  574.         $font = '';
  575.         if (!empty($this->_VarDumpConfVisual['fontface'])) {
  576.             $font .= ' face="'.$this->_VarDumpConfVisual['fontface'].'"';
  577.         }
  578.         if (!empty($this->_VarDumpConfVisual['fontsize'])) {
  579.             $font .= ' size="'.$this->_VarDumpConfVisual['fontsize'].'"';
  580.         }
  581.         for ($i = 1 ; $i <= 2 ; $i++) {
  582.             $fontTag = $font;
  583.             if (!empty($this->_VarDumpConfVisual['fontcolor'.$i])) {
  584.                 $fontTag .= ' color="'.$this->_VarDumpConfVisual['fontcolor'.$i].'"';
  585.             }
  586.             if (!empty($fontTag)) {
  587.                 $this->{'_VarDumpDisplayFont'.$i.'Start'} = '<font'.$fontTag.'>';
  588.                 $this->{'_VarDumpDisplayFont'.$i.'End'}   = '</font>';
  589.             } else {
  590.                 $this->{'_VarDumpDisplayFont'.$i.'Start'} = '';
  591.                 $this->{'_VarDumpDisplayFont'.$i.'End'}   = '';
  592.             }
  593.         }
  594.     }
  595.     // }}}
  596.  
  597.  
  598.     // {{{ _formatTableTEXT()
  599.     /**
  600.     * _formatTableTEXT() - Returns informations in text format
  601.     *
  602.     * This method returns all the informations collected on
  603.     * the submitted variables, in a text format
  604.     *
  605.     * @param array $array  The _VarDumpArray structure to display
  606.     * @param boolean $html Tell whether the output have to be html formated or not
  607.     */
  608.     function _formatTableTEXT($array,$html)
  609.     {
  610.         $tmp   = $this->_formatTableTEXTArray($array, $html);
  611.         $tmp   = ereg_replace("(^([\n])*)|(^(<br>)*)|(([\n])*$)|((<br>)*$)", '', $tmp);
  612.         if ($html) {
  613.             $table =
  614.                 '<pre>'.
  615.                 $this->_VarDumpDisplayFont1Start.
  616.                 $tmp.
  617.                 $this->_VarDumpDisplayFont1End.
  618.                 '</pre>';
  619.         } else {
  620.             $table = $tmp;
  621.         }
  622.         return $table;
  623.     }
  624.     // }}}
  625.  
  626.  
  627.     // {{{ _formatTableTEXTArray()
  628.     /**
  629.     * _formatTableTEXTArray() - Returns informations in text format
  630.     *
  631.     * This recursive method returns all the informations collected on
  632.     * the submitted variables, in a text format
  633.     *
  634.     * @param array $array      The _VarDumpArray structure to display
  635.     * @param boolean $html     Tell whether the output have to be html formated or not
  636.     * @param array $complete   Contains the width of each column
  637.     * @param int $level        Level of recursion
  638.     */
  639.     function _formatTableTEXTArray($array, $html = false, $complete = array(), $level = 0)
  640.     {
  641.         $lang=$this->lang;
  642.         $table = '';
  643.         if ($level > 0) {
  644.             $table .= $this->_formatTableTEXTSeparator($complete, ' ');
  645.         }
  646.         if (is_array($array) and !$this->_isSingleVariable($array)) {
  647.             $largeurCle  = 0;
  648.             $largeurType = 0;
  649.             foreach($array AS $key=>$val) {
  650.                 if (strlen($key) > $largeurCle) {
  651.                     $largeurCle = strlen($key);
  652.                 }
  653.                 if ($this->_isSingleVariable($val)) {
  654.                     if (strlen($val[VAR_DUMP_ARRAY_TYPE]) > $largeurType) {
  655.                         $largeurType = strlen($val[VAR_DUMP_ARRAY_TYPE]);
  656.                     }
  657.                 } else {
  658.                     $str = $this->messages['TYPE_ARRAY'][$lang].'('.count($val).')';
  659.                     $len = strlen($str);
  660.                     if ($len > $largeurType) {
  661.                         $largeurType = $len;
  662.                     }
  663.                 }
  664.             }
  665.             $compteur = count($array);
  666.             $k        = 0;
  667.             foreach($array AS $key=>$val) {
  668.                 if ($k == 0) {      
  669.                     $table .= $this->_formatTableTEXTSeparator($complete, '+');
  670.                 } elseif ($k == $compteur-1) {
  671.                     $table .= $this->_formatTableTEXTSeparator($complete, '+');
  672.                 } else {
  673.                     $table .= $this->_formatTableTEXTSeparator($complete, '|');
  674.                 }
  675.                 if ($this->_isSingleVariable($val)) {
  676.                     $table .=
  677.                         sprintf('%-'.$largeurCle.'s', $key).
  678.                         ' '.
  679.                         sprintf('%-'.$largeurType.'s', $val[VAR_DUMP_ARRAY_TYPE]).
  680.                         ' ('.
  681.                         $this->_VarDumpDisplayFont2Start.
  682.                         htmlspecialchars(rtrim($val[VAR_DUMP_ARRAY_VALUE])).
  683.                         $this->_VarDumpDisplayFont2End.
  684.                         ')';
  685.                 } else {
  686.                     $table .=
  687.                         sprintf('%-'.$largeurCle.'s', $key).
  688.                         ' '.
  689.                         sprintf('%-'.$largeurType.'s', $this->messages['TYPE_ARRAY'][$lang].'('.count($val).')');
  690.                     array_push($complete, $largeurCle);
  691.                     $table .= $this->_formatTableTEXTArray($val, $html, $complete, $level + 1);
  692.                     array_pop($complete);
  693.                 }
  694.                 $k++;
  695.             }
  696.         } else {
  697.             $table .=
  698.                 $array[VAR_DUMP_ARRAY_TYPE].
  699.                 ' ('.
  700.                 $this->_VarDumpDisplayFont2Start.
  701.                 htmlspecialchars(rtrim($array[VAR_DUMP_ARRAY_VALUE])).
  702.                 $this->_VarDumpDisplayFont2End.
  703.                 ')';
  704.         }
  705.         if ($level > 0) {
  706.             $table .= $this->_formatTableTEXTSeparator($complete, ' ');
  707.         }
  708.         return $table;
  709.     }
  710.     // }}}
  711.  
  712.  
  713.     // {{{ _formatTableTEXTSeparator()
  714.     /**
  715.     * _formatTableTEXTSeparator() - Returns the beginning of a line
  716.     *
  717.     * @param array $complete   Contains the width of each column
  718.     * @param char $displayLast Last character to display on the line
  719.     */
  720.     function _formatTableTEXTSeparator($complete, $displayLast = '')
  721.     {
  722.         $text  = "\n";
  723.         $count = count($complete);
  724.         if ($count > 0) {
  725.             $i = 0;
  726.             foreach($complete AS $larg) {
  727.                 $sep = $displayLast;
  728.                 if ($i < $count - 1) {
  729.                     $sep = '|';
  730.                 }
  731.                 $text .= str_repeat(' ', $larg + 1).$sep.' ';
  732.                 $i++;
  733.             }
  734.         }
  735.         return $text;
  736.     }
  737.     // }}}
  738.  
  739.  
  740.     // {{{ _formatTableHTML()
  741.     /**
  742.     * _formatTableHTML() - Returns informations in HTML format
  743.     *
  744.     * This method returns all the informations collected on
  745.     * the submitted variables, in a graphical format
  746.     *
  747.     * @param array $array The _VarDumpArray structure to display
  748.     * @param int   $level Level of recursion
  749.     */      
  750.     function _formatTableHTML($array, $level = 0)
  751.     {
  752.         $lang=$this->lang;
  753.         $table        = '';
  754.         $table_header = '';
  755.         $table_footer = '';
  756.         
  757.         $table_footer .= '</table>';
  758.         if ($this->_VarDumpConfVisual['bordersize'] > 0) {
  759.             $table_header .= '<table border=0 cellpadding='.$this->_VarDumpConfVisual['bordersize'].' cellspacing=0 bgcolor='.$this->_VarDumpConfVisual['bordercolor'].'><tr><td>';
  760.             $table_footer .= '</td></tr></table>';
  761.         }
  762.         $table_header .= '<table border=0 cellpadding='.$this->_VarDumpConfVisual['cellpadding'].' cellspacing='.$this->_VarDumpConfVisual['cellspacing'].'>';
  763.         
  764.         if (is_array($array)) {
  765.             if ($this->_isSingleVariable($array)) {
  766.  
  767.                 $table .= $this->_VarDumpDisplayFont1Start;
  768.                 $table .= $array[VAR_DUMP_ARRAY_TYPE];
  769.                 if (
  770.                     $array[VAR_DUMP_ARRAY_TYPE] != $this->messages['EMPTY_ARRAY'][$lang] and
  771.                     $array[VAR_DUMP_ARRAY_TYPE] != $this->messages['NOT_PARSED'][$lang]
  772.                 ) {
  773.                     if (!empty($array[VAR_DUMP_ARRAY_VALUE])) {
  774.                         $table .=
  775.                             ' ('.
  776.                             $this->_VarDumpDisplayFont2Start.
  777.                             htmlspecialchars((string) $array[VAR_DUMP_ARRAY_VALUE]).
  778.                             $this->_VarDumpDisplayFont2End.')';
  779.                     } elseif (
  780.                         (
  781.                             is_integer($array[VAR_DUMP_ARRAY_VALUE]) and
  782.                             $array[VAR_DUMP_ARRAY_VALUE] == 0
  783.                         ) or (
  784.                             is_string($array[VAR_DUMP_ARRAY_VALUE]) and
  785.                             $array[VAR_DUMP_ARRAY_VALUE] == '0'
  786.                         )
  787.                     ) {
  788.                         $table .=
  789.                             ' ('.
  790.                             $this->_VarDumpDisplayFont2Start.
  791.                             '0'.
  792.                             $this->_VarDumpDisplayFont2End.')';
  793.                     } else {
  794.                         $table .= ' ()';
  795.                     }
  796.                 }
  797.                 $table .= $this->_VarDumpDisplayFont1End;
  798.  
  799.             } else {
  800.                 if ($level==0 and count($array)==1 and !$this->_isSingleVariable($array[0]) and is_array($array[0])) {
  801.                     $display_border = false;
  802.                 } else {
  803.                     $display_border = true;
  804.                 }
  805.                 if ($display_border) {
  806.                     $table .= $table_header;
  807.                 }
  808.                 $c = 0;
  809.                 foreach($array as $key => $value) {
  810.                     if (is_array($value)) {
  811.                         if ($this->_isSingleVariable($value)) {
  812.                             if ($value[VAR_DUMP_ARRAY_TYPE]==$this->messages['NOT_PARSED'][$lang]) {
  813.                                 continue;
  814.                             } else {
  815.                                 $countValue = '';
  816.                             }
  817.                         } else {
  818.                             $countValue = ' ('.count($value).')';
  819.                         }
  820.                     } else {
  821.                         $countValue = '';
  822.                     }
  823.                     $bg='';
  824.                     if ($c==0) {
  825.                         if (!empty($this->_VarDumpConfVisual['color1'])) {
  826.                             $bg = ' bgcolor='.$this->_VarDumpConfVisual['color1'];
  827.                         }
  828.                     } else {
  829.                         if (!empty($this->_VarDumpConfVisual['color2'])) {
  830.                             $bg = ' bgcolor='.$this->_VarDumpConfVisual['color2'];
  831.                         }
  832.                     }
  833.                     if ($display_border) {
  834.                         $table .= '<tr'.$bg.' valign=top>';
  835.                         if ($level != 0 or count($array) != 1) {
  836.                             $table .= '<td>'.$this->_VarDumpDisplayFont1Start.$key.$countValue.$this->_VarDumpDisplayFont1End.'</td>';
  837.                         }
  838.                         $table .= '<td>'.$this->_formatTableHTML($value, $level+1).'</td>';
  839.                         $table .= '</tr>';
  840.                     } else {
  841.                         $table .= $this->_formatTableHTML($value, $level+1);
  842.                     }
  843.                     $c = 1-$c;
  844.                 }
  845.                 if ($display_border) {
  846.                     $table .= $table_footer;
  847.                 }
  848.             }
  849.         } else {        
  850.             $table .= $array;
  851.         }
  852.         return $table;
  853.     }
  854.     // }}}
  855.  
  856.  
  857.     // {{{ setDisplayMode()
  858.     /**
  859.     * setDisplayMode() - Set visual parameters
  860.     *
  861.     * This method set visual parameters for the rendering : border color
  862.     * and size, cells colors, padding and spacing of the table, font face,
  863.     * size and color.
  864.     *
  865.     * @param array $conf Display configuration
  866.     */
  867.     function setDisplayMode($conf = array())
  868.     {
  869.         $conf2=array_merge(
  870.             array(
  871.                 'bordercolor' => '#444444',
  872.                 'color1'      => '#dddddd',
  873.                 'color2'      => '#eeeeee',
  874.                 'bordersize'  => '1',
  875.                 'cellpadding' => '4',
  876.                 'cellspacing' => '0',
  877.                 'fontface'    => '',
  878.                 'fontsize'    => '',
  879.                 'fontcolor1'  => '',
  880.                 'fontcolor2'  => 'red'
  881.             ),
  882.             $conf
  883.         );
  884.         $this->_VarDumpConfVisual = $conf2;
  885.     }
  886.     // }}}
  887.     
  888.  
  889.     // {{{ setSkin()
  890.     /**
  891.     * setSkin() - Set visual parameters using a skin model
  892.     *
  893.     * This method set visual parameters using a skin model
  894.     *
  895.     * @param int $mode    Default display mode : Text or Html
  896.     * @param string $skin Name of the skin
  897.     *                     for the moment : default, green, red or blue
  898.     */
  899.     function setSkin($mode = VAR_DUMP_DISPLAY_MODE_HTML_TEXT, $skin = 'default')
  900.     {
  901.         switch ($mode) {
  902.  
  903.             case VAR_DUMP_DISPLAY_MODE_TEXT:
  904.                 $this->setDisplayMode(
  905.                     array(
  906.                         'fontface'    => '',
  907.                         'fontsize'    => '',
  908.                         'fontcolor1'  => '',
  909.                         'fontcolor2'  => ''
  910.                     )
  911.                 );
  912.                 break;
  913.  
  914.             case VAR_DUMP_DISPLAY_MODE_HTML_TEXT:
  915.  
  916.                 switch($skin) {
  917.                     case 'green':
  918.                         $this->setDisplayMode(array('fontcolor2' => '#55CC5F'));
  919.                         break;
  920.                     case 'red':
  921.                         $this->setDisplayMode(array('fontcolor2' => '#CC555F'));
  922.                         break;
  923.                     case 'blue':
  924.                         $this->setDisplayMode(array('fontcolor2' => '#5F55CC'));
  925.                         break;
  926.                     case 'default':
  927.                     default:
  928.                         $this->setDisplayMode();
  929.                         break;
  930.                 }
  931.                 break;
  932.  
  933.             case VAR_DUMP_DISPLAY_MODE_HTML_TABLE:
  934.             default:
  935.  
  936.                 switch($skin) {
  937.                     case 'green':
  938.                         $this->setDisplayMode(
  939.                             array(
  940.                                 'bordercolor' => '#2BB036',
  941.                                 'color1'      => '#55CC5F',
  942.                                 'color2'      => '#7FE888',
  943.                                 'bordersize'  => '1',
  944.                                 'cellpadding' => '4',
  945.                                 'cellspacing' => '0',
  946.                                 'fontface'    => '',
  947.                                 'fontsize'    => '',
  948.                                 'fontcolor1'  => '#FFFFFF',
  949.                                 'fontcolor2'  => '#FF00CC'
  950.                             )
  951.                         );
  952.                         break;
  953.                     case 'red':
  954.                         $this->setDisplayMode(
  955.                             array(
  956.                                 'bordercolor' => '#B02B36',
  957.                                 'color1'      => '#CC555F',
  958.                                 'color2'      => '#E87F88',
  959.                                 'bordersize'  => '1',
  960.                                 'cellpadding' => '4',
  961.                                 'cellspacing' => '0',
  962.                                 'fontface'    => '',
  963.                                 'fontsize'    => '',
  964.                                 'fontcolor1'  => '#FFFFFF',
  965.                                 'fontcolor2'  => '#FFCC00'
  966.                             )
  967.                         );
  968.                         break;
  969.                     case 'blue':
  970.                         $this->setDisplayMode(
  971.                             array(
  972.                                 'bordercolor' => '#362BB0',
  973.                                 'color1'      => '#5F55CC',
  974.                                 'color2'      => '#887FE8',
  975.                                 'bordersize'  => '1',
  976.                                 'cellpadding' => '4',
  977.                                 'cellspacing' => '0',
  978.                                 'fontface'    => '',
  979.                                 'fontsize'    => '',
  980.                                 'fontcolor1'  => '#FFFFFF',
  981.                                 'fontcolor2'  => '#CCFF00'
  982.                             )
  983.                         );
  984.                         break;
  985.                     case 'default':
  986.                     default:
  987.                         $this->setDisplayMode();
  988.                         break;
  989.                 }
  990.                 break;
  991.         }
  992.  
  993.     }
  994.     // }}}
  995.  
  996. }
  997.  
  998. ?>