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: *
83: * @param string $msg
84: *
85: * @throws cInvalidArgumentException
86: */
87: public function out($msg) {
88: if (cFileHandler::writeable($this->_sPathToFile)) {
89: $sDate = date('Y-m-d H:i:s');
90: cFileHandler::write($this->_sPathToFile, $sDate . ": " . $msg . "\n", true);
91: }
92: }
93:
94: /**
95: * Outputs contents of passed variable in a preformatted, readable way
96: *
97: * @param mixed $mVariable
98: * The variable to be displayed
99: * @param string $sVariableDescription [optional]
100: * The variable's name or description
101: * @param bool $bExit [optional]
102: * If set to true, your app will die() after output of current var
103: * @throws cInvalidArgumentException
104: */
105: public function show($mVariable, $sVariableDescription = '', $bExit = false) {
106: if (cFileHandler::writeable($this->_sPathToFile)) {
107: $sDate = date('Y-m-d H:i:s');
108: cFileHandler::write($this->_sPathToFile, '#################### ' . $sDate . ' ####################' . "\n", true);
109: cFileHandler::write($this->_sPathToFile, $sVariableDescription . "\n", true);
110: cFileHandler::write($this->_sPathToFile, print_r($mVariable, true) . "\n", true);
111: cFileHandler::write($this->_sPathToFile, '#################### /' . $sDate . ' ###################' . "\n\n", true);
112: }
113: }
114:
115: /**
116: * Interface implementation
117: *
118: * @param mixed $mVariable
119: * @param string $sVariableDescription [optional]
120: */
121: public function add($mVariable, $sVariableDescription = '') {
122: }
123:
124: /**
125: * Interface implementation
126: */
127: public function reset() {
128: }
129:
130: /**
131: * Interface implementation
132: */
133: public function showAll() {
134: }
135: }
136: