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

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