Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
4
// | PHP version 4                                                        |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2006 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@free.fr>                 |
17
// +----------------------------------------------------------------------+
18
 
19
/**
20
 * Wrapper for the var_dump function.
21
 *
22
 * " The var_dump function displays structured information about expressions
23
 * that includes its type and value. Arrays are explored recursively
24
 * with values indented to show structure. "
25
 *
26
 * The Var_Dump class captures the output of the var_dump function,
27
 * by using output control functions, and then uses external renderer
28
 * classes for displaying the result in various graphical ways :
29
 * simple text, HTML/XHTML text, HTML/XHTML table, XML, ...
30
 *
31
 * @category  PHP
32
 * @package   Var_Dump
33
 * @author    Frederic Poeydomenge <fpoeydomenge@free.fr>
34
 * @copyright 1997-2006 The PHP Group
35
 * @license   http://www.php.net/license/3_0.txt PHP License 3.0
36
 * @version   CVS: $Id: Table.php 233111 2007-04-02 09:38:10Z fredericpoeydome $
37
 * @link      http://pear.php.net/package/Var_Dump
38
 */
39
 
40
/**
41
 * Include the base class for all renderers
42
 */
43
 
44
require_once 'Var_Dump/Renderer/Common.php';
45
 
46
/**
47
 * A concrete renderer for Var_Dump
48
 *
49
 * Returns a table-based representation of a variable in HTML
50
 *
51
 * @category  PHP
52
 * @package   Var_Dump
53
 * @author    Frederic Poeydomenge <fpoeydomenge@free.fr>
54
 * @copyright 1997-2006 The PHP Group
55
 * @license   http://www.php.net/license/3_0.txt PHP License 3.0
56
 * @version   CVS: $Id: Table.php 233111 2007-04-02 09:38:10Z fredericpoeydome $
57
 * @link      http://pear.php.net/package/Var_Dump
58
 */
59
 
60
class Var_Dump_Renderer_Table extends Var_Dump_Renderer_Common
61
{
62
 
63
    /**
64
     * Default configuration options.
65
     *
66
     * Valid configuration options are :
67
     *     show_caption     : bool,    Show the caption or not
68
     *     show_eol         : string,  String to insert before a newline, or false
69
     *     before_num_key   : string,  Text to insert before a numerical key
70
     *     after_num_key    : string,  Text to insert after a numerical key
71
     *     before_str_key   : string,  Text to insert before a string key
72
     *     after_str_key    : string,  Text to insert after a string key
73
     *     before_type      : string,  Text to insert before a type
74
     *     after_type       : string,  Text to insert after a type
75
     *     before_value     : string,  Text to insert before a value
76
     *     after_value      : string,  Text to insert after a value
77
     *     start_table      : string,  Text to insert before the table
78
     *     end_table        : string,  Text to insert after the table
79
     *     start_tr         : string,  Text to insert before a row
80
     *     end_tr           : string,  Text to insert after a row
81
     *     start_tr_alt     : string,  Text to insert after an alternate row
82
     *     end_tr_alt       : string,  Text to insert after an alternate row
83
     *     start_td_key     : string,  Text to insert before the key cell
84
     *     end_td_key       : string,  Text to insert after the key cell
85
     *     start_td_type    : string,  Text to insert before the type cell
86
     *     end_td_type      : string,  Text to insert after the type cell
87
     *     start_td_value   : string,  Text to insert before the value cell
88
     *     end_td_value     : string,  Text to insert after the value cell
89
     *     start_td_colspan : string,  Text to insert before a group cell
90
     *     end_td_colspan   : string,  Text to insert after a group cell
91
     *     start_caption    : string,  Text to insert before the caption
92
     *     end_caption      : string,  Text to insert after the caption
93
     *
94
     * @var array
95
     * @access public
96
     */
97
    var $defaultOptions = array(
98
        'show_caption'     => TRUE,
99
        'show_eol'         => FALSE,
100
        'before_num_key'   => '',
101
        'after_num_key'    => '',
102
        'before_str_key'   => '',
103
        'after_str_key'    => '',
104
        'before_type'      => '',
105
        'after_type'       => '',
106
        'before_value'     => '',
107
        'after_value'      => '',
108
        'start_table'      => '<table>',
109
        'end_table'        => '</table>',
110
        'start_tr'         => '<tr>',
111
        'end_tr'           => '</tr>',
112
        'start_tr_alt'     => '<tr>',
113
        'end_tr_alt'       => '</tr>',
114
        'start_td_key'     => '<td>',
115
        'end_td_key'       => '</td>',
116
        'start_td_type'    => '<td>',
117
        'end_td_type'      => '</td>',
118
        'start_td_value'   => '<td>',
119
        'end_td_value'     => '</td>',
120
        'start_td_colspan' => '<td colspan="2">',
121
        'end_td_colspan'   => '</td>',
122
        'start_caption'    => '<caption>',
123
        'end_caption'      => '</caption>'
124
    );
125
 
126
    /**
127
     * Class constructor.
128
     *
129
     * @param array $options Parameters for the rendering.
130
     * @access public
131
     */
132
    function Var_Dump_Renderer_Table($options = array())
133
    {
134
        $this->setOptions($options);
135
    }
136
 
137
    /**
138
     * Returns the string representation of a variable
139
     *
140
     * @return string The string representation of the variable.
141
     * @access public
142
     */
143
    function toString()
144
    {
145
        if (count($this->family) == 1) {
146
            return $this->_toString_Single();
147
        } else {
148
            return $this->_toString_Array();
149
        }
150
    }
151
 
152
    /**
153
     * Returns the string representation of a single variable
154
     *
155
     * @return string The string representation of a single variable.
156
     * @access private
157
     */
158
    function _toString_Single()
159
    {
160
        $string = htmlspecialchars($this->value[0]);
161
        if ($this->options['show_eol'] !== FALSE) {
162
            $string = str_replace(
163
                "\n",
164
                $this->options['show_eol'] . "\n",
165
                $string
166
            );
167
        }
168
        return
169
            $this->options['start_table'] .
170
            $this->options['start_tr'] .
171
            $this->options['start_td_type'] .
172
            $this->options['before_type'] .
173
            htmlspecialchars($this->type[0]) .
174
            $this->options['after_type'] .
175
            $this->options['end_td_type'] .
176
            $this->options['start_td_value'] .
177
            $this->options['before_value'] .
178
            nl2br($string) .
179
            $this->options['after_value'] .
180
            $this->options['end_td_value'] .
181
            $this->options['end_tr'] .
182
            $this->options['end_table'];
183
    }
184
 
185
    /**
186
     * Returns the string representation of a multiple variable
187
     *
188
     * @return string The string representation of a multiple variable.
189
     * @access private
190
     */
191
    function _toString_Array()
192
    {
193
        $txt = '';
194
        $stack = array(0);
195
        $counter = count($this->family);
196
        for ($c = 0 ; $c < $counter ; $c++) {
197
            switch ($this->family[$c]) {
198
                case VAR_DUMP_START_GROUP :
199
                    array_push($stack, 0);
200
                    if ($this->depth[$c] > 0) {
201
                        $txt .= $this->options['start_td_colspan'];
202
                    }
203
                    $txt .= $this->options['start_table'];
204
                    if ($this->options['show_caption']) {
205
                        $txt .=
206
                            $this->options['start_caption'] .
207
                            htmlspecialchars($this->value[$c]) .
208
                            $this->options['end_caption'];
209
                    }
210
                    break;
211
                case VAR_DUMP_FINISH_GROUP :
212
                    array_pop($stack);
213
                    $txt .= $this->options['end_table'];
214
                    if ($this->depth[$c] > 0) {
215
                        $txt .=
216
                            $this->options['end_td_colspan'] .
217
                            $this->options['end_tr'];
218
                    }
219
                    break;
220
                case VAR_DUMP_START_ELEMENT_NUM :
221
                case VAR_DUMP_START_ELEMENT_STR :
222
                    array_push($stack, 1 - array_pop($stack));
223
                    $tr = (end($stack) == 1) ? 'start_tr' : 'start_tr_alt';
224
                    $comp = ($this->family[$c] == VAR_DUMP_START_ELEMENT_NUM) ? 'num' : 'str';
225
                    $txt .=
226
                        $this->options[$tr] .
227
                        $this->options['start_td_key'] .
228
                        $this->options['before_'.$comp.'_key'] .
229
                        htmlspecialchars($this->value[$c]) .
230
                        $this->options['after_'.$comp.'_key'] .
231
                        $this->options['end_td_key'];
232
                    break;
233
                case VAR_DUMP_FINISH_ELEMENT :
234
                case VAR_DUMP_FINISH_STRING :
235
                    $etr = (end($stack) == 1) ? 'end_tr' : 'end_tr_alt';
236
                    if (!is_null($this->value[$c])) {
237
                        $string = htmlspecialchars($this->value[$c]);
238
                        if ($this->options['show_eol'] !== FALSE) {
239
                            $string = str_replace(
240
                                "\n",
241
                                $this->options['show_eol'] . "\n",
242
                                $string
243
                            );
244
                        }
245
                        $txt .=
246
                            $this->options['start_td_type'] .
247
                            $this->options['before_type'] .
248
                            htmlspecialchars($this->type[$c]) .
249
                            $this->options['after_type'] .
250
                            $this->options['end_td_type'] .
251
                            $this->options['start_td_value'] .
252
                            $this->options['before_value'] .
253
                            nl2br($string) .
254
                            $this->options['after_value'] .
255
                            $this->options['end_td_value'] .
256
                            $this->options[$etr];
257
                    } else {
258
                        $txt .=
259
                            $this->options['start_td_colspan'] .
260
                            $this->options['before_type'] .
261
                            htmlspecialchars($this->type[$c]) .
262
                            $this->options['after_type'] .
263
                            $this->options['end_td_colspan'] .
264
                            $this->options[$etr];
265
                    }
266
                    break;
267
            }
268
        }
269
        return $txt;
270
    }
271
 
272
}
273
 
274
?>