Debug.inc
3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/**
* Debug generated XML
*
* @category Phpdocx
* @package debug
* @copyright Copyright (c) Narcea Producciones Multimedia S.L.
* (http://www.2mdc.com)
* @license LGPL
* @version 3.0
* @link http://www.phpdocx.com
* @since File available since Release 3.0
*/
class Debug
{
/**
*
* @access private
* @var int
*/
private $_active;
/**
*
* @access private
* @static
* @var string
*/
private static $_instance = null;
/**
*
* @access private
* @var array
*/
private $_messages;
/**
*
* @access private
* @var string
*/
private $_templateMessage;
/**
* Construct
*
* @access public
*/
public function __construct()
{
}
/**
* Destruct
*
* @access public
*/
public function __destruct()
{
}
/**
* Magic method, returns error messages
*
* @access public
* @return string Return found errors using a template
*/
public function __toString()
{
if ($this->_active) {
$this->generateTemplate();
return $this->_templateMessage;
}
}
/**
* Singleton, return instance of class
*
* @access public
* @return Debug
*/
public static function getInstance()
{
if (self::$_instance == NULL) {
self::$_instance = new Debug();
}
return self::$_instance;
}
/**
* Setter. Access to messages var
*
* @access public
* @param array $messages
*/
public function setMessages($messages)
{
$this->_messages = $messages;
}
/**
* Getter. Access to messages var
*
* @access public
* @return array
*/
public function getMessages()
{
return $this->_messages;
}
/**
* Setter. Enable debug
*
* @access public
* @param int $active
*/
public function setActive($active)
{
$this->_active = $active;
}
/**
* Getter. Return debug status
*
* @access public
* @return int
*/
public function getActive()
{
return $this->_active;
}
/**
* Add a new mesagge to the pool of _messages
*
* @access public
* @param mixed $message
*/
public function addMessage($message)
{
$this->_messages[] = $message;
}
/**
* Enable debug
*
* @access public
* @deprecated deprecated since version 2.0
*/
public function enableDebug()
{
$this->_messages = array();
$this->setActive(1);
}
/**
* Disable debug
*
* @access public
* @deprecated deprecated since version 2.0
*/
public function fDisableDebug()
{
$this->setActive(0);
}
/**
* Assign template to use
*
* @access protected
* @deprecated deprecated since version 2.0
*/
protected function generateTemplate()
{
$this->_templateMessage = '<html xmlns="http://www.w3.org/1999/xhtml"'
. 'xml:lang="es" lang="es"><head></head><body><ul>';
foreach ($this->_messages as $dat) {
if (is_array($dat)) {
foreach ($this->_messages as $unkDatArr) {
if (is_array($unkDatArr)) {
foreach ($unkDatArr as $xmlErrorDat) {
$this->_templateMessage .= '<li>'
. $xmlErrorDat->message . '</li>';
}
} else {
$this->_templateMessage .= '<li>' . $unkDatArr
. '</li>';
}
}
} else {
$this->_templateMessage .= '<li>' . $dat . '</li>';
}
}
$this->_templateMessage .= '</ul></body></html>';
}
}