1: <?php
2:
3: /**
4: * This file contains the static debugger class.
5: *
6: * @package Core
7: * @subpackage Debug
8: *
9: * @author Rudi Bieller
10: * @author Murat Purc <murat@purc.de>
11: * @copyright four for business AG <www.4fb.de>
12: * @license http://www.contenido.org/license/LIZENZ.txt
13: * @link http://www.4fb.de
14: * @link http://www.contenido.org
15: */
16:
17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
18:
19: /**
20: * Debugger class
21: *
22: * @package Core
23: * @subpackage Debug
24: */
25: class cDebug {
26:
27: /**
28: *
29: * @var string
30: */
31: const DEBUGGER_VISIBLE = 'visible';
32:
33: /**
34: *
35: * @var string
36: */
37: const DEBUGGER_VISIBLE_ADV = 'visible_adv';
38:
39: /**
40: *
41: * @var string
42: */
43: const DEBUGGER_HIDDEN = 'hidden';
44:
45: /**
46: *
47: * @var string
48: */
49: const DEBUGGER_FILE = 'file';
50:
51: /**
52: *
53: * @var string
54: */
55: const DEBUGGER_VISIBLE_AND_FILE = 'vis_and_file';
56:
57: /**
58: *
59: * @var string
60: */
61: const DEBUGGER_DEVNULL = 'devnull';
62:
63: /**
64: * Default debugger, defined in system settings
65: *
66: * @var string
67: */
68: protected static $_defaultDebuggerName;
69:
70: /**
71: * Returns instance of debugger.
72: * If not defined, it returns the debugger from the current system settings.
73: *
74: * @param string $sType [optional]
75: * The debugger to get, empty string to get debugger defined in system settings
76: * @throws cInvalidArgumentException
77: * If type of debugger is unknown
78: * @return cDebugInterface
79: */
80: public static function getDebugger($sType = '') {
81: if (empty($sType)) {
82: $sType = self::_getSystemSettingDebugger();
83: }
84:
85: $oDebugger = NULL;
86: switch ($sType) {
87: case self::DEBUGGER_VISIBLE:
88: $oDebugger = cDebugVisible::getInstance();
89: break;
90: case self::DEBUGGER_VISIBLE_ADV:
91: $oDebugger = cDebugVisibleAdv::getInstance();
92: break;
93: case self::DEBUGGER_HIDDEN:
94: $oDebugger = cDebugHidden::getInstance();
95: break;
96: case self::DEBUGGER_FILE:
97: $oDebugger = cDebugFile::getInstance();
98: break;
99: case self::DEBUGGER_VISIBLE_AND_FILE:
100: $oDebugger = cDebugFileAndVisAdv::getInstance();
101: break;
102: case self::DEBUGGER_DEVNULL:
103: $oDebugger = cDebugDevNull::getInstance();
104: break;
105: default:
106: throw new cInvalidArgumentException('This type of debugger is unknown to cDebug: ' . $sType);
107: break;
108: }
109:
110: return $oDebugger;
111: }
112:
113: /**
114: * Prints a debug message if the settings allow it.
115: * The debug messages will be
116: * in a textrea in the header and in the file debuglog.txt. All messages are
117: * immediately
118: * written to the filesystem but they will only show up when
119: * cDebug::showAll() is called.
120: *
121: * @param string $message
122: * Message to display.
123: * NOTE: You can use buildStackString to show stacktraces
124: *
125: * @throws cInvalidArgumentException
126: */
127: public static function out($message) {
128: self::getDebugger()->out($message);
129: }
130:
131: /**
132: * Adds a variable to the debugger.
133: * This variable will be watched.
134: *
135: * @param mixed $var
136: * A variable or an object
137: * @param string $label [optional]
138: * An optional description for the variable
139: * @throws cInvalidArgumentException
140: */
141: public static function add($var, $label = '') {
142: self::getDebugger()->add($var, $label);
143: }
144:
145: /**
146: * Prints the cached debug messages to the screen
147: *
148: * @throws cInvalidArgumentException
149: */
150: public static function showAll() {
151: self::getDebugger()->showAll();
152: }
153:
154: /**
155: * Returns default debugger name.
156: *
157: * @return string
158: */
159: public static function getDefaultDebuggerName() {
160: return self::_getSystemSettingDebugger();
161: }
162:
163: /**
164: * Returns the debugger defined in system settings.
165: *
166: * @return string
167: */
168: protected static function _getSystemSettingDebugger() {
169: if (isset(self::$_defaultDebuggerName)) {
170: return self::$_defaultDebuggerName;
171: }
172: self::$_defaultDebuggerName = self::DEBUGGER_DEVNULL;
173: if (getSystemProperty('debug', 'debug_to_file') == 'true') {
174: self::$_defaultDebuggerName = self::DEBUGGER_FILE;
175: } else if (getSystemProperty('debug', 'debug_to_screen') == 'true') {
176: self::$_defaultDebuggerName = self::DEBUGGER_VISIBLE_ADV;
177: }
178: if ((getSystemProperty('debug', 'debug_to_screen') == 'true') && (getSystemProperty('debug', 'debug_to_file') == 'true')) {
179: self::$_defaultDebuggerName = self::DEBUGGER_VISIBLE_AND_FILE;
180: }
181:
182: return self::$_defaultDebuggerName;
183: }
184: }
185: