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

Source for file Var_Dump.php

Documentation is available at Var_Dump.php

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

Documentation generated on Mon, 11 Mar 2019 10:16:33 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.