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