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