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