1: <?php
2: /**
3: * This file contains the file and vis adv debug class.
4: *
5: * @package Core
6: * @subpackage Debug
7: * @version SVN Revision $Rev:$
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 and to show info on screen.
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 cDebugFileAndVisAdv extends cDebugVisibleAdv {
28:
29: /**
30: * Singleton instance
31: *
32: * @var cDebugFileAndVisAdv
33: * @todo should be private
34: */
35: protected static $_instance;
36:
37: /**
38: *
39: * @var array
40: */
41: private $_aItems;
42:
43: /**
44: *
45: * @var string
46: */
47: private $_filePathName;
48:
49: /**
50: * Return singleton instance.
51: *
52: * @return cDebugFileAndVisAdv
53: */
54: public static function getInstance() {
55: if (self::$_instance == NULL) {
56: self::$_instance = new cDebugFileAndVisAdv();
57: }
58: return self::$_instance;
59: }
60:
61: /**
62: * Constructor
63: */
64: private function __construct() {
65: global $cfg;
66: $this->_aItems = array();
67: $this->_filePathName = $cfg['path']['contenido_logs'] . 'debug.log';
68: }
69:
70: /**
71: * (non-PHPdoc)
72: *
73: * @see cDebugVisibleAdv::out()
74: */
75: public function out($msg) {
76: parent::out($msg);
77:
78: $sDate = date('Y-m-d H:i:s');
79: cFileHandler::write($this->_filePathName, $sDate . ": " . $msg . "\n", true);
80: }
81:
82: /**
83: * (non-PHPdoc)
84: *
85: * @see cDebugVisibleAdv::show()
86: */
87: public function show($mVariable, $sVariableDescription = '', $bExit = false) {
88: parent::show($mVariable, $sVariableDescription, $bExit);
89:
90: if (is_writeable($this->_filePathName)) {
91: $sDate = date('Y-m-d H:i:s');
92: $sContent = '#################### ' . $sDate . ' ####################' . "\n" . $sVariableDescription . "\n" . print_r($mVariable, true) . "\n" . '#################### /' . $sDate . ' ###################' . "\n\n";
93: cFileHandler::write($this->_filePathName, $sContent, true);
94: }
95: }
96: }
97: