* @license http://www.contenido.org/license/LIZENZ.txt * @link http://www.4fb.de * @link http://www.contenido.org * * {@internal * created 2008-05-20 * * $Id$: * }} * */ if(!defined('CON_FRAMEWORK')) { die('Illegal call'); } include_once('IDebug.php'); class Debug_VisibleAdv implements IDebug, Countable { static private $_instance; private $_aItems; private $_bIsOffline = false; /** * Constructor * @access private */ private function __construct() { $this->_aItems = array(); } /** * static * @access public */ static public function getInstance() { if (self::$_instance == null) { self::$_instance = new Debug_VisibleAdv(); } return self::$_instance; } public function switchOffline($bOffline) { if(is_bool($bOffline)) { $this->_bIsOffline = $bOffline; } } /** * Add a Debug item to internal collection. * @access public * @param mixed $mVariable * @param string $sVariableDescription * @return void; */ public function add($mVariable, $sVariableDescription = '') { if($this->_bIsOffline) return; $oItem = new Debug_VisibleAdv_Item(); $oItem->setValue($mVariable); $oItem->setDescription($sVariableDescription); $this->_aItems[] = $oItem; } /** * Reset internal collection with Debug items. * @access public * @return void */ public function reset() { $this->_aItems = array(); } /** * Outputs all Debug items in collection to screen in a HTML Box at left top of page. * @access public * @return void */ public function showAll() { if($this->_bIsOffline) return; if ($this->count() > 0) { $sHtml = ' '; $sHtml .= '
con dbg (x)
'; echo $sHtml; } } /** * Prepares Debug item value for output as string representation. * @access private * @param mixed $mValue * @return string */ private function _prepareValue($mValue) { $bTextarea = false; $bPlainText = false; $sReturn = ''; if (is_array($mValue)) { if (sizeof($mValue) > 10) { $bTextarea = true; } else { $bPlainText = true; } } if (is_object($mValue)) { $bTextarea = ($this->_useXDebug())?false:true; } if (is_string($mValue)) { if (preg_match('/<(.*)>/', $mValue)) { if (strlen($mValue) > 40) { $bTextarea = true; } else { $bPlainText = true; $mValue = clHtmlSpecialChars($mValue); } } else { $bPlainText = true; } } if ($bTextarea === true) { $sReturn .= ''; } elseif ($bPlainText === true) { $sReturn .= ''; } else { $sReturn .= ''; } return $sReturn; } /** * Implemenation of Countable interface * @access public * @return int */ public function count() { return sizeof($this->_aItems); } /** * Outputs contents of passed variable in a preformatted, readable way * * @access public * @param mixed $mVariable The variable to be displayed * @param string $sVariableDescription The variable's name or description * @param boolean $bExit If set to true, your app will die() after output of current var * @return void */ public function show($mVariable, $sVariableDescription='', $bExit = false) { if($this->_bIsOffline) return; try { $oDbgVisible = DebuggerFactory::getDebugger('visible'); } catch (Exception $e) { //throw $e; echo $e->getMessage(); } $oDbgVisible->show($mVariable, $sVariableDescription, $bExit); } private function _useXDebug() { if(function_exists("xdebug_is_enabled")) { return (xdebug_is_enabled() === true)?true:false; } return false; } } /** * An object representing one Debug item of a Debug_VisibleBlock. */ class Debug_VisibleAdv_Item { private $_mValue; private $_sDescription; /** * Set value of item * @access public * @return void */ public function setValue($mValue) { $this->_mValue = $mValue; } /** * Set name/description of item * @access public * @return void */ public function setDescription($sDescription) { $this->_sDescription = $sDescription; } /** * Get value of item * @access public * @return mixed */ public function getValue() { return $this->_mValue; } /** * Get name/description of item * @access public * @return string */ public function getDescription() { return $this->_sDescription; } } ?>