1: <?php
2:
3: /**
4: * This file contains the file and vis adv 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 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 to create an instance of this class.
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: * Writes a line.
72: *
73: * @see cDebugInterface::out()
74: * @param string $msg
75: */
76: public function out($msg) {
77: parent::out($msg);
78:
79: $sDate = date('Y-m-d H:i:s');
80: cFileHandler::write($this->_filePathName, $sDate . ": " . $msg . "\n", true);
81: }
82:
83: /**
84: * Outputs contents of passed variable in a preformatted, readable way.
85: *
86: * @see cDebugVisibleAdv::show()
87: * @param mixed $mVariable
88: * The variable to be displayed.
89: * @param string $sVariableDescription [optional]
90: * The variable's name or description.
91: * @param bool $bExit [optional]
92: * If set to true, your app will die() after output of current var.
93: */
94: public function show($mVariable, $sVariableDescription = '', $bExit = false) {
95: parent::show($mVariable, $sVariableDescription, $bExit);
96:
97: if (is_writeable($this->_filePathName)) {
98: $sDate = date('Y-m-d H:i:s');
99: $sContent = '#################### ' . $sDate . ' ####################' . "\n" . $sVariableDescription . "\n" . print_r($mVariable, true) . "\n" . '#################### /' . $sDate . ' ###################' . "\n\n";
100: cFileHandler::write($this->_filePathName, $sContent, true);
101: }
102: }
103: }
104: