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