1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31:
32: class cDebugVisibleAdv implements cDebugInterface, Countable {
33:
34: 35: 36: 37: 38:
39: private static $_instance;
40:
41: 42: 43: 44:
45: private $_aItems;
46:
47: 48: 49: 50:
51: private $_buffer;
52:
53: 54: 55: 56: 57:
58: public static function getInstance() {
59: if (self::$_instance == NULL) {
60: self::$_instance = new cDebugVisibleAdv();
61: }
62:
63: return self::$_instance;
64: }
65:
66: 67: 68:
69: private function __construct() {
70: $this->_aItems = array();
71: }
72:
73: 74: 75: 76: 77: 78:
79: public function add($mVariable, $sVariableDescription = '') {
80: $oItem = new cDebugVisibleAdvItem();
81: $oItem->setValue($mVariable);
82: $oItem->setDescription($sVariableDescription);
83: $this->_aItems[] = $oItem;
84: }
85:
86: 87: 88:
89: public function reset() {
90: $this->_aItems = array();
91: }
92:
93: 94: 95: 96: 97:
98: public function out($sText) {
99: $this->_buffer .= $sText . "\n";
100: }
101:
102: 103: 104: 105:
106: public function showAll() {
107: global $cfg;
108:
109: $sHtml = "";
110: if ($this->count() > 0) {
111: $tpl = new cTemplate();
112:
113: $i = 1;
114: foreach ($this->_aItems as $oItem) {
115: $sItemName = strlen($oItem->getDescription()) > 0? $oItem->getDescription() : ('debug item #' . $i);
116: $sItemValue = $this->_prepareValue($oItem->getValue());
117:
118: $tpl->set("d", "DBG_ITEM_COUNT", $i);
119: $tpl->set("d", "DBG_ITEM_NAME", $sItemName);
120: $tpl->set("d", "DBG_ITEM_VALUE", $sItemValue);
121: $tpl->next();
122:
123: ++$i;
124: }
125: $sHtml .= $tpl->generate($cfg["path"]["templates"] . $cfg["template"]["debug_visibleadv"], true);
126: }
127:
128: $buffer = str_replace("\'", "\\'", $this->_buffer);
129: $buffer = str_replace("\"", "\\\"", $buffer);
130: $buffer = str_replace("\n", '\n', $buffer);
131: $buffer = str_replace(chr(13), "", $buffer);
132:
133: $tpl = new cTemplate();
134: $tpl->set("s", "DBG_MESSAGE_CONTENT", $buffer);
135: $sHtml .= $tpl->generate($cfg["path"]["templates"] . $cfg["templates"]["debug_header"], true);
136:
137: echo $sHtml;
138: }
139:
140: 141: 142: 143: 144: 145: 146:
147: private function _prepareValue($mValue) {
148: $bTextarea = false;
149: $bPlainText = false;
150: $sReturn = '';
151: if (is_array($mValue)) {
152: if (sizeof($mValue) > 10) {
153: $bTextarea = true;
154: } else {
155: $bPlainText = true;
156: }
157: }
158: if (is_object($mValue)) {
159: $bTextarea = true;
160: }
161: if (is_string($mValue)) {
162: if (preg_match('/<(.*)>/', $mValue)) {
163: if (strlen($mValue) > 40) {
164: $bTextarea = true;
165: } else {
166: $bPlainText = true;
167: $mValue = conHtmlSpecialChars($mValue);
168: }
169: } else {
170: $bPlainText = true;
171: }
172: }
173:
174: if ($bTextarea === true) {
175: $sReturn .= '<textarea rows="14" cols="100">';
176: } elseif ($bPlainText === true) {
177: $sReturn .= '<pre>';
178: } else {
179: $sReturn .= '<pre>';
180: }
181:
182: if (is_array($mValue)) {
183: $sReturn .= print_r($mValue, true);
184: } else {
185: ob_start();
186: var_dump($mValue);
187: $sReturn .= ob_get_contents();
188: ob_end_clean();
189: }
190:
191: if ($bTextarea === true) {
192: $sReturn .= '</textarea>';
193: } elseif ($bPlainText === true) {
194: $sReturn .= '</pre>';
195: } else {
196: $sReturn .= '</pre>';
197: }
198:
199: return $sReturn;
200: }
201:
202: 203: 204: 205: 206:
207: public function count() {
208: return sizeof($this->_aItems);
209: }
210:
211: 212: 213: 214: 215: 216: 217: 218:
219: public function show($mVariable, $sVariableDescription = '', $bExit = false) {
220: try {
221: $oDbgVisible = cDebug::getDebugger(cDebug::DEBUGGER_VISIBLE);
222: } catch (Exception $e) {
223:
224: echo $e->getMessage();
225: }
226: $oDbgVisible->show($mVariable, $sVariableDescription, $bExit);
227: }
228: }
229:
230: 231: 232: 233: 234: 235:
236: class cDebugVisibleAdvItem {
237:
238: 239: 240: 241:
242: private $_mValue;
243:
244: 245: 246: 247:
248: private $_sDescription;
249:
250: 251: 252: 253: 254:
255: public function getValue() {
256: return $this->_mValue;
257: }
258:
259: 260: 261: 262: 263:
264: public function setValue($mValue) {
265: $this->_mValue = $mValue;
266: }
267:
268: 269: 270: 271: 272:
273: public function getDescription() {
274: return $this->_sDescription;
275: }
276:
277: 278: 279: 280: 281:
282: public function setDescription($sDescription) {
283: $this->_sDescription = $sDescription;
284: }
285: }