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.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.      *     before_num_key   : string,  Text to insert before a numerical key
  39.      *     after_num_key    : string,  Text to insert after a numerical key
  40.      *     before_str_key   : string,  Text to insert before a string key
  41.      *     after_str_key    : string,  Text to insert after a string key
  42.      *     before_type      : string,  Text to insert before a type
  43.      *     after_type       : string,  Text to insert after a type
  44.      *     before_value     : string,  Text to insert before a value
  45.      *     after_value      : string,  Text to insert after a value
  46.      *     start_table      : string,  Text to insert before the table
  47.      *     end_table        : string,  Text to insert after the table
  48.      *     start_tr         : string,  Text to insert before a row
  49.      *     end_tr           : string,  Text to insert after a row
  50.      *     start_tr_alt     : string,  Text to insert after an alternate row
  51.      *     end_tr_alt       : string,  Text to insert after an alternate row
  52.      *     start_td_key     : string,  Text to insert before the key cell
  53.      *     end_td_key       : string,  Text to insert after the key cell
  54.      *     start_td_type    : string,  Text to insert before the type cell
  55.      *     end_td_type      : string,  Text to insert after the type cell
  56.      *     start_td_value   : string,  Text to insert before the value cell
  57.      *     end_td_value     : string,  Text to insert after the value cell
  58.      *     start_td_colspan : string,  Text to insert before a group cell
  59.      *     end_td_colspan   : string,  Text to insert after a group cell
  60.      *     start_caption    : string,  Text to insert before the caption
  61.      *     end_caption      : string,  Text to insert after the caption
  62.      * @var    array 
  63.      * @access public
  64.      */
  65.     var $defaultOptions = array(
  66.         'show_caption'     => TRUE,
  67.         'before_num_key'   => '',
  68.         'after_num_key'    => '',
  69.         'before_str_key'   => '',
  70.         'after_str_key'    => '',
  71.         'before_type'      => '',
  72.         'after_type'       => '',
  73.         'before_value'     => '',
  74.         'after_value'      => '',
  75.         'start_table'      => '<table>',
  76.         'end_table'        => '</table>',
  77.         'start_tr'         => '<tr>',
  78.         'end_tr'           => '</tr>',
  79.         'start_tr_alt'     => '<tr>',
  80.         'end_tr_alt'       => '</tr>',
  81.         'start_td_key'     => '<td>',
  82.         'end_td_key'       => '</td>',
  83.         'start_td_type'    => '<td>',
  84.         'end_td_type'      => '</td>',
  85.         'start_td_value'   => '<td>',
  86.         'end_td_value'     => '</td>',
  87.         'start_td_colspan' => '<td colspan="2">',
  88.         'end_td_colspan'   => '</td>',
  89.         'start_caption'    => '<caption>',
  90.         'end_caption'      => '</caption>'
  91.     );
  92.  
  93.     // {{{ constructor
  94.     /**
  95.      * Class constructor.
  96.      * @param  array  $options Parameters for the rendering.
  97.      * @access public
  98.      */
  99.     function Var_Dump_Renderer_Table($options = array())
  100.     {
  101.         parent::Var_Dump_Renderer($options);
  102.     }
  103.     // }}}
  104.  
  105.     // {{{ toString()
  106.     /**
  107.      * Returns the string representation of a variable
  108.      * @return string The string representation of the variable.
  109.      * @access public
  110.      */
  111.     function toString()
  112.     {
  113.         if (count($this->family== 1{
  114.             return $this->_toString_Single();
  115.         else {
  116.             return $this->_toString_Array();
  117.         }
  118.     }
  119.     // }}}
  120.  
  121.     // {{{ _toString_Single()
  122.     /**
  123.      * Returns the string representation of a single variable
  124.      * @return string The string representation of a single variable.
  125.      * @access public
  126.      */
  127.     function _toString_Single()
  128.     {
  129.         return
  130.             $this->options['start_table'.
  131.             $this->options['start_tr'.
  132.             $this->options['start_td_type'.
  133.             $this->options['before_type'.
  134.             htmlspecialchars($this->type[0].
  135.             $this->options['after_type'.
  136.             $this->options['end_td_type'.
  137.             $this->options['start_td_value'.
  138.             $this->options['before_value'.
  139.             htmlspecialchars($this->value[0].
  140.             $this->options['after_value'.
  141.             $this->options['end_td_value'.
  142.             $this->options['end_tr'.
  143.             $this->options['end_table'];
  144.     }
  145.     // }}}
  146.  
  147.     // {{{ _toString_Array()
  148.     /**
  149.      * Returns the string representation of a multiple variable
  150.      * @return string The string representation of a multiple variable.
  151.      * @access public
  152.      */
  153.     function _toString_Array()
  154.     {
  155.         $txt '';
  156.         $stack = array(0);
  157.         $counter count($this->family);
  158.         for ($c = 0 ; $c $counter $c++{
  159.             switch ($this->family[$c]{
  160.                 case VAR_DUMP_START_GROUP :
  161.                     array_push($stack0);
  162.                     if ($this->depth[$c> 0{
  163.                         $txt .= $this->options['start_td_colspan'];
  164.                     }
  165.                     $txt .= $this->options['start_table'];
  166.                     if ($this->options['show_caption']{
  167.                         $txt .=
  168.                             $this->options['start_caption'.
  169.                             htmlspecialchars($this->value[$c].
  170.                             $this->options['end_caption'];
  171.                     }
  172.                     break;
  173.                 case VAR_DUMP_FINISH_GROUP :
  174.                     array_pop($stack);
  175.                     $txt .= $this->options['end_table'];
  176.                     if ($this->depth[$c> 0{
  177.                         $txt .=
  178.                             $this->options['end_td_colspan'.
  179.                             $this->options['end_tr'];
  180.                     }
  181.                     break;
  182.                 case VAR_DUMP_START_ELEMENT_NUM :
  183.                 case VAR_DUMP_START_ELEMENT_STR :
  184.                     array_push($stack1 - array_pop($stack));
  185.                     $tr (end($stack== 1'start_tr' 'start_tr_alt';
  186.                     $comp ($this->family[$c== VAR_DUMP_START_ELEMENT_NUM'num' 'str';
  187.                     $txt .=
  188.                         $this->options[$tr.
  189.                         $this->options['start_td_key'.
  190.                         $this->options['before_'.$comp.'_key'.
  191.                         htmlspecialchars($this->value[$c].
  192.                         $this->options['after_'.$comp.'_key'.
  193.                         $this->options['end_td_key'];
  194.                     break;
  195.                 case VAR_DUMP_FINISH_ELEMENT :
  196.                 case VAR_DUMP_FINISH_ELEMENT_NL :
  197.                     $etr (end($stack== 1'end_tr' 'end_tr_alt';
  198.                     if (!empty($this->value[$c])) {
  199.                         $txt .=
  200.                             $this->options['start_td_type'.
  201.                             $this->options['before_type'.
  202.                             htmlspecialchars($this->type[$c].
  203.                             $this->options['after_type'.
  204.                             $this->options['end_td_type'.
  205.                             $this->options['start_td_value'.
  206.                             $this->options['before_value'.
  207.                             nl2br(htmlspecialchars($this->value[$c])) .
  208.                             $this->options['after_value'.
  209.                             $this->options['end_td_value'.
  210.                             $this->options[$etr];
  211.                     else {
  212.                         $txt .=
  213.                             $this->options['start_td_colspan'.
  214.                             $this->options['before_type'.
  215.                             htmlspecialchars($this->type[$c].
  216.                             $this->options['after_type'.
  217.                             $this->options['end_td_colspan'.
  218.                             $this->options[$etr];
  219.                     }
  220.                     break;
  221.             }
  222.         }
  223.         return $txt;
  224.     }
  225.     // }}}
  226.  
  227. }
  228.  
  229. ?>

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