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

Documentation generated on Mon, 11 Mar 2019 14:23:43 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.