| // +----------------------------------------------------------------------+ // // $Id$ require_once 'Var_Dump/Renderer/Common.php'; /** * A concrete renderer for Var_Dump * * Returns a representation of a variable in XML * DTD : $PEARDIR/data/Var_Dump/renderer-xml.dtd * * @package Var_Dump * @category PHP * @author Frederic Poeydomenge */ class Var_Dump_Renderer_XML extends Var_Dump_Renderer_Common { /** * Class constructor. * * @param array $options Parameters for the rendering. * @access public */ function Var_Dump_Renderer_XML($options = array()) { $this->setOptions($options); } /** * Returns the string representation of a variable * * @return string The string representation of the variable. * @access public */ function toString() { if (count($this->family) == 1) { return $this->_toString_Single(); } else { return $this->_toString_Array(); } } /** * Returns the string representation of a single variable * * @return string The string representation of a single variable. * @access private */ function _toString_Single() { return '' . '' . htmlspecialchars($this->type[0]) . '' . '' . htmlspecialchars($this->value[0]) . '' . ''; } /** * Returns the string representation of a multiple variable * * @return string The string representation of a multiple variable. * @access private */ function _toString_Array() { $txt = ''; $counter = count($this->family); $depth = 0; for ($c = 0 ; $c < $counter ; $c++) { switch ($this->family[$c]) { case VAR_DUMP_START_GROUP : if ($this->depth[$c] > 0) { $txt .= $this->_spacer($depth) . 'group' . "\n" . $this->_spacer($depth++) . '' . "\n"; } $txt .= $this->_spacer($depth) . '' . "\n"; break; case VAR_DUMP_FINISH_GROUP : $txt .= $this->_spacer($depth) . '' . "\n"; if ($this->depth[$c] > 0) { $txt .= $this->_spacer(--$depth) . '' . "\n" . $this->_spacer(--$depth) . '' . "\n"; $depth--; } break; case VAR_DUMP_START_ELEMENT_NUM : case VAR_DUMP_START_ELEMENT_STR : $txt .= $this->_spacer(++$depth) . '' . "\n" . $this->_spacer(++$depth) . '' . htmlspecialchars($this->value[$c]) . '' . "\n"; break; case VAR_DUMP_FINISH_ELEMENT : case VAR_DUMP_FINISH_STRING : $txt .= $this->_spacer($depth) . '' . htmlspecialchars($this->type[$c]) . '' . "\n". $this->_spacer($depth--) . '' . htmlspecialchars($this->value[$c]) . '' . "\n" . $this->_spacer($depth--) . '' . "\n"; break; } } return $txt; } /** * Returns a spacer string to prefix the line * * @param integer $depth Depth level. * @return string Spacer string * @access private */ function _spacer($depth) { return str_repeat(' ', $depth << 1); } } ?>