Elgg  Version 2.3
Timer.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg;
3 
9 class Timer {
10  const MARKER_BEGIN = ':begin';
11  const MARKER_END = ':end';
12 
13  private $times = [];
14 
21  public function begin(array $keys) {
22  $this->getTreeNode($keys)[self::MARKER_BEGIN] = microtime();
23  }
24 
31  public function end(array $keys) {
32  $this->getTreeNode($keys)[self::MARKER_END] = microtime();
33  }
34 
41  public function hasEnded(array $keys) {
42  $node = $this->getTreeNode($keys);
43  return isset($node[self::MARKER_END]);
44  }
45 
51  public function getTimes() {
52  return $this->times;
53  }
54 
61  private function &getTreeNode(array $keys) {
62  $arr =& $this->times;
63 
64  foreach ($keys as $key) {
65  if (!isset($arr[$key])) {
66  $arr[$key] = [];
67  }
68  $arr =& $arr[$key];
69  }
70 
71  return $arr;
72  }
73 }
begin(array $keys)
Record the start time of a period.
Definition: Timer.php:21
getTimes()
Get the tree of recorded start/end times.
Definition: Timer.php:51
Capture timing info for profiling.
Definition: Timer.php:9
$keys
Definition: access.php:34
Save menu items.
$key
Definition: summary.php:34
end(array $keys)
Record the end time of a period.
Definition: Timer.php:31
hasEnded(array $keys)
Has the end of the period been recorded?
Definition: Timer.php:41