-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebug.php
203 lines (179 loc) · 4.47 KB
/
Debug.php
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
201
202
203
<?php
/**
* Zend_Debug
*/
require_once 'Zend/Debug.php';
/**
* This Ztools_Debug component is used to easily create debug points
* and later retrieve all leg data in one HTML friendly block.
* Information includes leg number, leg duration and entered debug message.
*
* @copyright 2010 Artur Gajewski
* @license http://framework.zend.com/license BSD License
* @version Release: @package_version@
* @link http://ztools.arturgajewski.com
* @since Class available since Release 1.0.4
*/
class Ztools_Debug
{
/**
* Timestamp of start time
*
* @var float $_start
*/
private $_debugChainTitle;
/**
* Timestamp of start time
*
* @var float $_start
*/
private $_start;
/**
* Timestamp of last leg
*
* @var float $_end
*/
private $_end;
/**
* Total amount of time recorded
*
* @var float $_total
*/
private $_total;
/**
* Container for each recorded leg
*
* @var array $_legs
*/
private $_legs = array();
/**
* The Constructor
*/
public function __construct($debugChainTitle = '')
{
$this->_start = microtime(true);
$this->_debugChainTitle = $debugChainTitle;
}
/**
* Get debug chain's title
*
* @return string
*/
public function getTitle()
{
return $this->_debugChainTitle;
}
/**
* Set debug chain's title
*
* @param string $value
* @return Ztools_Debug
*/
public function setTitle($value)
{
$this->_debugChainTitle = $value;
return $this;
}
/**
* Generates stripped output.
*/
public function add($message = '', $echo = false)
{
$current = microtime(true);
$this->_end = microtime(true);
if (!isset($this->_legs[sizeof($this->_legs)-1]["legtime"])) {
$legTime = $this->_start - $current;
} else {
$legTime = $current - $this->_legs[sizeof($this->_legs)-1]["starttime"];
}
$totalTime = $current - $this->_start;
if ($legTime < 0) {
$legTime = $totalTime;
}
$this->_total = $totalTime;
$this->_legs[] = array("message" => $message,
"starttime" => $current,
"legtime" => $legTime,
"totaltime" => $totalTime);
if ($echo == true) {
$this->getLastLeg();
} else {
return $this->getLastLeg(false);
}
}
/**
* Get information about generated debug chain
*
* @return array
*/
public function getInfo()
{
return array( "title" => $this->_debugChainTitle,
"start" => $this->_start,
"end" => $this->_end,
"total" => $this->_total,
"legs" => $this->_legs);
}
/**
* Echo last leg's information.
* @param boolean $echo
* @return string
*/
public function getLastLeg($echo = true)
{
$leg = $this->_legs[sizeOf($this->_legs) -1];
if ($echo == true) {
Zend_Debug::dump($this->_legs[sizeOf($this->_legs) -1], null, true);
} else {
return Zend_Debug::dump($this->_legs[sizeOf($this->_legs) -1], null, false);
}
}
/**
* Get the size of generated debug chain
*
* @return int
*/
public function count()
{
return sizeOf($this->_legs);
}
/**
* Get elapsed time since beginning of chain
*
* @return int
*/
public function getElapsedTime()
{
return $this->_total;
}
/**
* Dump the whole chain data into HTML or other output.
*
* @param boolean $echo
* @param boolean $reset
* @return string
*/
public function dump($echo = true, $reset = false, $newTitle = null)
{
$data = $this->getInfo();
if ($reset) {
$this->reset($newTitle);
}
if ($echo == true) {
Zend_Debug::dump($data, null, true);
} else {
return Zend_Debug::dump($data, null, false);
}
}
/**
* Reset the debug chain
*/
public function reset($newTitle = null)
{
if ($newTitle != null) {
$this->_debugChainTitle = $newTitle;
}
$this->_start = microtime(true);
$this->_legs = array();
}
}