forked from idno/known
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTotalTimer.php
46 lines (33 loc) · 1.11 KB
/
TotalTimer.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
<?php
/**
* Simple totalising timer
* Useful for loops and calculating how much time is in each section
*
* @package idno
* @subpackage core
*/
namespace Idno\Stats {
class TotalTimer extends Timer {
private static $timerTotals = [];
public static function stop($timer) {
$value = parent::value($timer);
if (!isset(static::$timerTotals[$timer]))
static::$timerTotals[$timer] = $value;
else
static::$timerTotals[$timer] += $value;
return static::$timerTotals[$timer];
}
/**
* Return the TOTAL timer value.
* @param type $timer
* @return type
* @throws \RuntimeException
*/
public static function value($timer) {
if (isset( static::$timerTotals[$timer])) {
return static::$timerTotals[$timer];
}
throw new \RuntimeException(\Idno\Core\Idno::site()->language()->_("Timer %s has not been started.", [$timer]));
}
}
}