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

Source for file Table.php

Documentation is available at Table.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2004 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at the following url:           |
  11. // | http://www.php.net/license/3_0.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 'Var_Dump/Renderer/Common.php';
  22.  
  23. /**
  24.  * A concrete renderer for Var_Dump
  25.  *
  26.  * Returns a table-based representation of a variable in HTML
  27.  *
  28.  * @package Var_Dump
  29.  * @category PHP
  30.  * @author Frederic Poeydomenge <frederic.poeydomenge@free.fr>
  31.  */
  32.  
  33. {
  34.  
  35.     /**
  36.      * Default configuration options.
  37.      *     show_caption     : bool,    Show the caption or not
  38.      *     show_eol         : string,  String to insert before a newline, or false
  39.      *     before_num_key   : string,  Text to insert before a numerical key
  40.      *     after_num_key    : string,  Text to insert after a numerical key
  41.      *     before_str_key   : string,  Text to insert before a string key
  42.      *     after_str_key    : string,  Text to insert after a string key
  43.      *     before_type      : string,  Text to insert before a type
  44.      *     after_type       : string,  Text to insert after a type
  45.      *     before_value     : string,  Text to insert before a value
  46.      *     after_value      : string,  Text to insert after a value
  47.      *     start_table      : string,  Text to insert before the table
  48.      *     end_table        : string,  Text to insert after the table
  49.      *     start_tr         : string,  Text to insert before a row
  50.      *     end_tr           : string,  Text to insert after a row
  51.      *     start_tr_alt     : string,  Text to insert after an alternate row
  52.      *     end_tr_alt       : string,  Text to insert after an alternate row
  53.      *     start_td_key     : string,  Text to insert before the key cell
  54.      *     end_td_key       : string,  Text to insert after the key cell
  55.      *     start_td_type    : string,  Text to insert before the type cell
  56.      *     end_td_type      : string,  Text to insert after the type cell
  57.      *     start_td_value   : string,  Text to insert before the value cell
  58.      *     end_td_value     : string,  Text to insert after the value cell
  59.      *     start_td_colspan : string,  Text to insert before a group cell
  60.      *     end_td_colspan   : string,  Text to insert after a group cell
  61.      *     start_caption    : string,  Text to insert before the caption
  62.      *     end_caption      : string,  Text to insert after the caption
  63.      * @var array 
  64.      * @access public
  65.      */
  66.     var $defaultOptions = array(
  67.         'show_caption'     => TRUE,
  68.         'show_eol'         => FALSE,
  69.         'before_num_key'   => '',
  70.         'after_num_key'    => '',
  71.         'before_str_key'   => '',
  72.         'after_str_key'    => '',
  73.         'before_type'      => '',
  74.         'after_type'       => '',
  75.         'before_value'     => '',
  76.         'after_value'      => '',
  77.         'start_table'      => '<table>',
  78.         'end_table'        => '</table>',
  79.         'start_tr'         => '<tr>',
  80.         'end_tr'           => '</tr>',
  81.         'start_tr_alt'     => '<tr>',
  82.         'end_tr_alt'       => '</tr>',
  83.         'start_td_key'     => '<td>',
  84.         'end_td_key'       => '</td>',
  85.         'start_td_type'    => '<td>',
  86.         'end_td_type'      => '</td>',
  87.         'start_td_value'   => '<td>',
  88.         'end_td_value'     => '</td>',
  89.         'start_td_colspan' => '<td colspan="2">',
  90.         'end_td_colspan'   => '</td>',
  91.         'start_caption'    => '<caption>',
  92.         'end_caption'      => '</caption>'
  93.     );
  94.  
  95.     /**
  96.      * Class constructor.
  97.      * @param array $options Parameters for the rendering.
  98.      * @access public
  99.      */
  100.     function Var_Dump_Renderer_Table($options = array())
  101.     {
  102.         $this->setOptions($options);
  103.     }
  104.  
  105.     /**
  106.      * Returns the string representation of a variable
  107.      * @return string The string representation of the variable.
  108.      * @access public
  109.      */
  110.     function toString()
  111.     {
  112.         if (count($this->family== 1{
  113.             return $this->_toString_Single();
  114.         else {
  115.             return $this->_toString_Array();
  116.         }
  117.     }
  118.  
  119.     /**
  120.      * Returns the string representation of a single variable
  121.      * @return string The string representation of a single variable.
  122.      * @access private
  123.      */
  124.     function _toString_Single()
  125.     {
  126.         $string htmlspecialchars($this->value[0]);
  127.         if ($this->options['show_eol'!== FALSE{
  128.             $string str_replace(
  129.                 "\n",
  130.                 $this->options['show_eol'"\n",
  131.                 $string
  132.             );
  133.         }
  134.         return
  135.             $this->options['start_table'.
  136.             $this->options['start_tr'.
  137.             $this->options['start_td_type'.
  138.             $this->options['before_type'.
  139.             htmlspecialchars($this->type[0].
  140.             $this->options['after_type'.
  141.             $this->options['end_td_type'.
  142.             $this->options['start_td_value'.
  143.             $this->options['before_value'.
  144.             nl2br($string.
  145.             $this->options['after_value'.
  146.             $this->options['end_td_value'.
  147.             $this->options['end_tr'.
  148.             $this->options['end_table'];
  149.     }
  150.  
  151.     /**
  152.      * Returns the string representation of a multiple variable
  153.      * @return string The string representation of a multiple variable.
  154.      * @access private
  155.      */
  156.     function _toString_Array()
  157.     {
  158.         $txt '';
  159.         $stack = array(0);
  160.         $counter count($this->family);
  161.         for ($c = 0 ; $c $counter $c++{
  162.             switch ($this->family[$c]{
  163.                 case VAR_DUMP_START_GROUP :
  164.                     array_push($stack0);
  165.                     if ($this->depth[$c> 0{
  166.                         $txt .= $this->options['start_td_colspan'];
  167.                     }
  168.                     $txt .= $this->options['start_table'];
  169.                     if ($this->options['show_caption']{
  170.                         $txt .=
  171.                             $this->options['start_caption'.
  172.                             htmlspecialchars($this->value[$c].
  173.                             $this->options['end_caption'];
  174.                     }
  175.                     break;
  176.                 case VAR_DUMP_FINISH_GROUP :
  177.                     array_pop($stack);
  178.                     $txt .= $this->options['end_table'];
  179.                     if ($this->depth[$c> 0{
  180.                         $txt .=
  181.                             $this->options['end_td_colspan'.
  182.                             $this->options['end_tr'];
  183.                     }
  184.                     break;
  185.                 case VAR_DUMP_START_ELEMENT_NUM :
  186.                 case VAR_DUMP_START_ELEMENT_STR :
  187.                     array_push($stack1 - array_pop($stack));
  188.                     $tr (end($stack== 1'start_tr' 'start_tr_alt';
  189.                     $comp ($this->family[$c== VAR_DUMP_START_ELEMENT_NUM'num' 'str';
  190.                     $txt .=
  191.                         $this->options[$tr.
  192.                         $this->options['start_td_key'.
  193.                         $this->options['before_'.$comp.'_key'.
  194.                         htmlspecialchars($this->value[$c].
  195.                         $this->options['after_'.$comp.'_key'.
  196.                         $this->options['end_td_key'];
  197.                     break;
  198.                 case VAR_DUMP_FINISH_ELEMENT :
  199.                 case VAR_DUMP_FINISH_STRING :
  200.                     $etr (end($stack== 1'end_tr' 'end_tr_alt';
  201.                     if (!is_null($this->value[$c])) {
  202.                         $string htmlspecialchars($this->value[$c]);
  203.                         if ($this->options['show_eol'!== FALSE{
  204.                             $string str_replace(
  205.                                 "\n",
  206.                                 $this->options['show_eol'"\n",
  207.                                 $string
  208.                             );
  209.                         }
  210.                         $txt .=
  211.                             $this->options['start_td_type'.
  212.                             $this->options['before_type'.
  213.                             htmlspecialchars($this->type[$c].
  214.                             $this->options['after_type'.
  215.                             $this->options['end_td_type'.
  216.                             $this->options['start_td_value'.
  217.                             $this->options['before_value'.
  218.                             nl2br($string.
  219.                             $this->options['after_value'.
  220.                             $this->options['end_td_value'.
  221.                             $this->options[$etr];
  222.                     else {
  223.                         $txt .=
  224.                             $this->options['start_td_colspan'.
  225.                             $this->options['before_type'.
  226.                             htmlspecialchars($this->type[$c].
  227.                             $this->options['after_type'.
  228.                             $this->options['end_td_colspan'.
  229.                             $this->options[$etr];
  230.                     }
  231.                     break;
  232.             }
  233.         }
  234.         return $txt;
  235.     }
  236.  
  237. }
  238.  
  239. ?>

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