1: <?php
2: /**
3: * This file contains the static debugger class.
4: *
5: * @package Core
6: * @subpackage Debug
7: * @version SVN Revision $Rev:$
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: const DEBUGGER_VISIBLE = 'visible';
28: const DEBUGGER_VISIBLE_ADV = 'visible_adv';
29: const DEBUGGER_HIDDEN = 'hidden';
30: const DEBUGGER_FILE = 'file';
31: const DEBUGGER_VISIBLE_AND_FILE = 'vis_and_file';
32: const DEBUGGER_DEVNULL = 'devnull';
33:
34: /**
35: * Default debugger, defined in system settings
36: * @var string
37: */
38: protected static $_defaultDebuggerName;
39:
40: /**
41: * Returns instance of debugger. If not defined, it returns the debugger from the current system settings.
42: *
43: * @param string $sType The debugger to get, empty string to get debugger defined in system settings
44: *
45: * @throws cInvalidArgumentException If type of debugger is unknown
46: * @return cDebugInterface
47: */
48: public static function getDebugger($sType = '') {
49: if (empty($sType)) {
50: $sType = self::_getSystemSettingDebugger();
51: }
52:
53: $oDebugger = NULL;
54: switch ($sType) {
55: case self::DEBUGGER_VISIBLE:
56: $oDebugger = cDebugVisible::getInstance();
57: break;
58: case self::DEBUGGER_VISIBLE_ADV:
59: $oDebugger = cDebugVisibleAdv::getInstance();
60: break;
61: case self::DEBUGGER_HIDDEN:
62: $oDebugger = cDebugHidden::getInstance();
63: break;
64: case self::DEBUGGER_FILE:
65: $oDebugger = cDebugFile::getInstance();
66: break;
67: case self::DEBUGGER_VISIBLE_AND_FILE:
68: $oDebugger = cDebugFileAndVisAdv::getInstance();
69: break;
70: case self::DEBUGGER_DEVNULL:
71: $oDebugger = cDebugDevNull::getInstance();
72: break;
73: default:
74: throw new cInvalidArgumentException('This type of debugger is unknown to cDebug: ' . $sType);
75: break;
76: }
77:
78: return $oDebugger;
79: }
80:
81: /**
82: * Prints a debug message if the settings allow it. The debug messages will be
83: * in a textrea in the header and in the file debuglog.txt. All messages are immediately
84: * written to the filesystem but they will only show up when cDebug::showAll() is called.
85: *
86: * @param string $message Message to display. NOTE: You can use buildStackString to show stacktraces
87: */
88: public static function out($message) {
89: self::getDebugger()->out($message);
90: }
91:
92: /**
93: * Adds a variable to the debugger. This variable will be watched.
94: *
95: * @param mixed $var A variable or an object
96: * @param string $label An optional description for the variable
97: */
98: public static function add($var, $label = '') {
99: self::getDebugger()->add($var, $label);
100: }
101:
102: /**
103: * Prints the cached debug messages to the screen
104: */
105: public static function showAll() {
106: self::getDebugger()->showAll();
107: }
108:
109: /**
110: * Returns default debugger name.
111: * @return string
112: */
113: public static function getDefaultDebuggerName() {
114: return self::_getSystemSettingDebugger();
115: }
116:
117: /**
118: * Returns the debugger defined in system settings.
119: * @return string
120: */
121: protected static function _getSystemSettingDebugger() {
122: if (isset(self::$_defaultDebuggerName)) {
123: return self::$_defaultDebuggerName;
124: }
125: self::$_defaultDebuggerName = self::DEBUGGER_DEVNULL;
126: if (getSystemProperty('debug', 'debug_to_file') == 'true') {
127: self::$_defaultDebuggerName = self::DEBUGGER_FILE;
128: } else if (getSystemProperty('debug', 'debug_to_screen') == 'true') {
129: self::$_defaultDebuggerName = self::DEBUGGER_VISIBLE_ADV;
130: }
131: if ((getSystemProperty('debug', 'debug_to_screen') == 'true') && (getSystemProperty('debug', 'debug_to_file') == 'true')) {
132: self::$_defaultDebuggerName = self::DEBUGGER_VISIBLE_AND_FILE;
133: }
134:
135: return self::$_defaultDebuggerName;
136: }
137:
138: }
139: