1: <?php
2:
3: /**
4: * This file contains the file and vis adv 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 and to show info on screen.
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 cDebugFileAndVisAdv extends cDebugVisibleAdv {
29:
30: /**
31: * Singleton instance
32: *
33: * @var cDebugFileAndVisAdv
34: * @todo should be private
35: */
36: protected static $_instance;
37:
38: /**
39: *
40: * @var array
41: */
42: private $_aItems;
43:
44: /**
45: *
46: * @var string
47: */
48: private $_filePathName;
49:
50: /**
51: * Return singleton instance.
52: *
53: * @return cDebugFileAndVisAdv
54: */
55: public static function getInstance() {
56: if (self::$_instance == NULL) {
57: self::$_instance = new cDebugFileAndVisAdv();
58: }
59: return self::$_instance;
60: }
61:
62: /**
63: * Constructor
64: */
65: private function __construct() {
66: global $cfg;
67: $this->_aItems = array();
68: $this->_filePathName = $cfg['path']['contenido_logs'] . 'debug.log';
69: }
70:
71: /**
72: * Writes a line.
73: *
74: * @see cDebugInterface::out()
75: * @param string $msg
76: */
77: public function out($msg) {
78: parent::out($msg);
79:
80: $sDate = date('Y-m-d H:i:s');
81: cFileHandler::write($this->_filePathName, $sDate . ": " . $msg . "\n", true);
82: }
83:
84: /**
85: * Outputs contents of passed variable in a preformatted, readable way.
86: *
87: * @see cDebugVisibleAdv::show()
88: * @param mixed $mVariable
89: * The variable to be displayed.
90: * @param string $sVariableDescription [optional]
91: * The variable's name or description.
92: * @param bool $bExit [optional]
93: * If set to true, your app will die() after output of current var.
94: */
95: public function show($mVariable, $sVariableDescription = '', $bExit = false) {
96: parent::show($mVariable, $sVariableDescription, $bExit);
97:
98: if (is_writeable($this->_filePathName)) {
99: $sDate = date('Y-m-d H:i:s');
100: $sContent = '#################### ' . $sDate . ' ####################' . "\n" . $sVariableDescription . "\n" . print_r($mVariable, true) . "\n" . '#################### /' . $sDate . ' ###################' . "\n\n";
101: cFileHandler::write($this->_filePathName, $sContent, true);
102: }
103: }
104: }
105: