| 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: XML.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 representation of a variable in XML
|
|
|
50 |
* DTD : PEARDIR/data/Var_Dump/renderer-xml.dtd
|
|
|
51 |
*
|
|
|
52 |
* @category PHP
|
|
|
53 |
* @package Var_Dump
|
|
|
54 |
* @author Frederic Poeydomenge <fpoeydomenge@free.fr>
|
|
|
55 |
* @copyright 1997-2006 The PHP Group
|
|
|
56 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
|
|
57 |
* @version CVS: $Id: XML.php 233111 2007-04-02 09:38:10Z fredericpoeydome $
|
|
|
58 |
* @link http://pear.php.net/package/Var_Dump
|
|
|
59 |
*/
|
|
|
60 |
|
|
|
61 |
class Var_Dump_Renderer_XML extends Var_Dump_Renderer_Common
|
|
|
62 |
{
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Class constructor.
|
|
|
66 |
*
|
|
|
67 |
* @param array $options Parameters for the rendering.
|
|
|
68 |
* @access public
|
|
|
69 |
*/
|
|
|
70 |
function Var_Dump_Renderer_XML($options = array())
|
|
|
71 |
{
|
|
|
72 |
$this->setOptions($options);
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* Returns the string representation of a variable
|
|
|
77 |
*
|
|
|
78 |
* @return string The string representation of the variable.
|
|
|
79 |
* @access public
|
|
|
80 |
*/
|
|
|
81 |
function toString()
|
|
|
82 |
{
|
|
|
83 |
if (count($this->family) == 1) {
|
|
|
84 |
return $this->_toString_Single();
|
|
|
85 |
} else {
|
|
|
86 |
return $this->_toString_Array();
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Returns the string representation of a single variable
|
|
|
92 |
*
|
|
|
93 |
* @return string The string representation of a single variable.
|
|
|
94 |
* @access private
|
|
|
95 |
*/
|
|
|
96 |
function _toString_Single()
|
|
|
97 |
{
|
|
|
98 |
return
|
|
|
99 |
'<element>' .
|
|
|
100 |
'<type>' . htmlspecialchars($this->type[0]) . '</type>' .
|
|
|
101 |
'<value>' . htmlspecialchars($this->value[0]) . '</value>' .
|
|
|
102 |
'</element>';
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* Returns the string representation of a multiple variable
|
|
|
107 |
*
|
|
|
108 |
* @return string The string representation of a multiple variable.
|
|
|
109 |
* @access private
|
|
|
110 |
*/
|
|
|
111 |
function _toString_Array()
|
|
|
112 |
{
|
|
|
113 |
$txt = '';
|
|
|
114 |
$counter = count($this->family);
|
|
|
115 |
$depth = 0;
|
|
|
116 |
for ($c = 0 ; $c < $counter ; $c++) {
|
|
|
117 |
switch ($this->family[$c]) {
|
|
|
118 |
case VAR_DUMP_START_GROUP :
|
|
|
119 |
if ($this->depth[$c] > 0) {
|
|
|
120 |
$txt .=
|
|
|
121 |
$this->_spacer($depth) . '<type>group</type>' . "\n" .
|
|
|
122 |
$this->_spacer($depth++) . '<value>' . "\n";
|
|
|
123 |
}
|
|
|
124 |
$txt .=
|
|
|
125 |
$this->_spacer($depth) .
|
|
|
126 |
'<group caption="' . htmlspecialchars($this->value[$c]) .
|
|
|
127 |
'">' . "\n";
|
|
|
128 |
break;
|
|
|
129 |
case VAR_DUMP_FINISH_GROUP :
|
|
|
130 |
$txt .= $this->_spacer($depth) . '</group>' . "\n";
|
|
|
131 |
if ($this->depth[$c] > 0) {
|
|
|
132 |
$txt .=
|
|
|
133 |
$this->_spacer(--$depth) . '</value>' . "\n" .
|
|
|
134 |
$this->_spacer(--$depth) . '</element>' . "\n";
|
|
|
135 |
$depth--;
|
|
|
136 |
}
|
|
|
137 |
break;
|
|
|
138 |
case VAR_DUMP_START_ELEMENT_NUM :
|
|
|
139 |
case VAR_DUMP_START_ELEMENT_STR :
|
|
|
140 |
$txt .=
|
|
|
141 |
$this->_spacer(++$depth) . '<element>' . "\n" .
|
|
|
142 |
$this->_spacer(++$depth) . '<key>' .
|
|
|
143 |
htmlspecialchars($this->value[$c]) .
|
|
|
144 |
'</key>' . "\n";
|
|
|
145 |
break;
|
|
|
146 |
case VAR_DUMP_FINISH_ELEMENT :
|
|
|
147 |
case VAR_DUMP_FINISH_STRING :
|
|
|
148 |
$txt .=
|
|
|
149 |
$this->_spacer($depth) . '<type>' .
|
|
|
150 |
htmlspecialchars($this->type[$c]) .
|
|
|
151 |
'</type>' . "\n".
|
|
|
152 |
$this->_spacer($depth--) . '<value>' .
|
|
|
153 |
htmlspecialchars($this->value[$c]) .
|
|
|
154 |
'</value>' . "\n" .
|
|
|
155 |
$this->_spacer($depth--) . '</element>' . "\n";
|
|
|
156 |
break;
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
return $txt;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
/**
|
|
|
163 |
* Returns a spacer string to prefix the line
|
|
|
164 |
*
|
|
|
165 |
* @param integer $depth Depth level.
|
|
|
166 |
* @return string Spacer string
|
|
|
167 |
* @access private
|
|
|
168 |
*/
|
|
|
169 |
function _spacer($depth) {
|
|
|
170 |
return str_repeat(' ', $depth << 1);
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
?>
|