1: <?php
2:
3: /**
4: * This file contains the file debug class.
5: *
6: * @package Core
7: * @subpackage Debug
8: * @version SVN Revision $Rev:$
9: *
10: * @author Rudi Bieller
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: * Debug object to write info to a file.
21: * In case you cannot output directly to screen when debugging a live system,
22: * this object writes
23: * the info to a file located in /data/logs/debug.log.
24: *
25: * @package Core
26: * @subpackage Debug
27: */
28: class cDebugFile implements cDebugInterface {
29:
30: /**
31: * Singleton instance
32: *
33: * @var cDebugFile
34: */
35: private static $_instance;
36:
37: /**
38: *
39: * @var string
40: */
41: private $_sPathToLogs;
42:
43: /**
44: *
45: * @var string
46: */
47: private $_sFileName;
48:
49: /**
50: *
51: * @var string
52: */
53: private $_sPathToFile;
54:
55: /**
56: * Return singleton instance.
57: *
58: * @return cDebugFile
59: */
60: public static function getInstance() {
61: if (self::$_instance == NULL) {
62: self::$_instance = new cDebugFile();
63: }
64: return self::$_instance;
65: }
66:
67: /**
68: * Constructor
69: * Opens filehandle for debug-logfile
70: */
71: private function __construct() {
72: global $cfg; // omfg, I know... TODO
73: $this->_sPathToLogs = $cfg['path']['contenido_logs'];
74: $this->_sFileName = 'debug.log';
75: $this->_sPathToFile = $this->_sPathToLogs . $this->_sFileName;
76: }
77:
78: /**
79: * Writes a line.
80: *
81: * @see cDebugInterface::out()
82: * @param string $msg
83: */
84: public function out($msg) {
85: if (cFileHandler::writeable($this->_sPathToFile)) {
86: $sDate = date('Y-m-d H:i:s');
87: cFileHandler::write($this->_sPathToFile, $sDate . ": " . $msg . "\n", true);
88: }
89: }
90:
91: /**
92: * Outputs contents of passed variable in a preformatted, readable way
93: *
94: * @param mixed $mVariable
95: * The variable to be displayed
96: * @param string $sVariableDescription [optional]
97: * The variable's name or description
98: * @param bool $bExit [optional]
99: * If set to true, your app will die() after output of current var
100: */
101: public function show($mVariable, $sVariableDescription = '', $bExit = false) {
102: if (cFileHandler::writeable($this->_sPathToFile)) {
103: $sDate = date('Y-m-d H:i:s');
104: cFileHandler::write($this->_sPathToFile, '#################### ' . $sDate . ' ####################' . "\n", true);
105: cFileHandler::write($this->_sPathToFile, $sVariableDescription . "\n", true);
106: cFileHandler::write($this->_sPathToFile, print_r($mVariable, true) . "\n", true);
107: cFileHandler::write($this->_sPathToFile, '#################### /' . $sDate . ' ###################' . "\n\n", true);
108: }
109: }
110:
111: /**
112: * Interface implementation
113: *
114: * @param mixed $mVariable
115: * @param string $sVariableDescription [optional]
116: */
117: public function add($mVariable, $sVariableDescription = '') {
118: }
119:
120: /**
121: * Interface implementation
122: */
123: public function reset() {
124: }
125:
126: /**
127: * Interface implementation
128: */
129: public function showAll() {
130: }
131: }
132: