1: <?php
2:
3: /**
4: * This file contains the file debug class.
5: *
6: * @package Core
7: * @subpackage Debug
8: *
9: * @author Rudi Bieller
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * Debug object to write info to a file.
20: * In case you cannot output directly to screen when debugging a live system,
21: * this object writes
22: * the info to a file located in /data/logs/debug.log.
23: *
24: * @package Core
25: * @subpackage Debug
26: */
27: class cDebugFile implements cDebugInterface {
28:
29: /**
30: * Singleton instance
31: *
32: * @var cDebugFile
33: */
34: private static $_instance;
35:
36: /**
37: *
38: * @var string
39: */
40: private $_sPathToLogs;
41:
42: /**
43: *
44: * @var string
45: */
46: private $_sFileName;
47:
48: /**
49: *
50: * @var string
51: */
52: private $_sPathToFile;
53:
54: /**
55: * Return singleton instance.
56: *
57: * @return cDebugFile
58: */
59: public static function getInstance() {
60: if (self::$_instance == NULL) {
61: self::$_instance = new cDebugFile();
62: }
63: return self::$_instance;
64: }
65:
66: /**
67: * Constructor to create an instance of this class.
68: *
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: