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: public static function out($message) {
126: self::getDebugger()->out($message);
127: }
128:
129: /**
130: * Adds a variable to the debugger.
131: * This variable will be watched.
132: *
133: * @param mixed $var
134: * A variable or an object
135: * @param string $label [optional]
136: * An optional description for the variable
137: */
138: public static function add($var, $label = '') {
139: self::getDebugger()->add($var, $label);
140: }
141:
142: /**
143: * Prints the cached debug messages to the screen
144: */
145: public static function showAll() {
146: self::getDebugger()->showAll();
147: }
148:
149: /**
150: * Returns default debugger name.
151: *
152: * @return string
153: */
154: public static function getDefaultDebuggerName() {
155: return self::_getSystemSettingDebugger();
156: }
157:
158: /**
159: * Returns the debugger defined in system settings.
160: *
161: * @return string
162: */
163: protected static function _getSystemSettingDebugger() {
164: if (isset(self::$_defaultDebuggerName)) {
165: return self::$_defaultDebuggerName;
166: }
167: self::$_defaultDebuggerName = self::DEBUGGER_DEVNULL;
168: if (getSystemProperty('debug', 'debug_to_file') == 'true') {
169: self::$_defaultDebuggerName = self::DEBUGGER_FILE;
170: } else if (getSystemProperty('debug', 'debug_to_screen') == 'true') {
171: self::$_defaultDebuggerName = self::DEBUGGER_VISIBLE_ADV;
172: }
173: if ((getSystemProperty('debug', 'debug_to_screen') == 'true') && (getSystemProperty('debug', 'debug_to_file') == 'true')) {
174: self::$_defaultDebuggerName = self::DEBUGGER_VISIBLE_AND_FILE;
175: }
176:
177: return self::$_defaultDebuggerName;
178: }
179: }
180: