Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
log_iterator.inc
1 <?php
29 {
30 
31 
32  protected $offset;
33  protected $logname;
34  protected $rotation_index;
35  protected $total_size;
36 
37 
45  function __construct($logname, $rotation_index=NULL)
46  {
47  $this->offset = 0;
48  $this->logname = $logname;
49  $this->rotation_index = $rotation_index;
50 
51  $log_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('log_manager');
52  $this->total_size = $log_manager->getLogSize($this->logname, $this->rotation_index);
53 
54  if (empty($this->total_size)) {
55  $this->total_size = 0;
56  }
57 
58  }//end constructor
59 
60 
69  public function getNextEntry()
70  {
71  if ($this->offset < $this->total_size) {
72  $log_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('log_manager');
73  $line =& $log_manager->getLogLine($this->logname, $this->rotation_index, $this->offset);
74  $line_offset = array_get_index($line, 'offset', FALSE);
75 
76  if ($line_offset != FALSE && $line_offset >= 0) {
77  $this->offset = $line_offset;
78  }
79 
80  return array_get_index($line, 'line', FALSE);
81 
82  } else {
83  return FALSE;
84  }
85 
86  }//end getNextEntry()
87 
88 
97  public function getLastEntry()
98  {
99  $last_entry = FALSE;
100  while($line=$this->getNextEntry()) {
101  if ($line) {
102  $last_entry = $line;
103  }
104  }
105 
106  return $last_entry;
107 
108  }//end function getLastEntry()
109 
110 
125  public function &getCurrentProgress()
126  {
127  $result = Array(
128  'current' => $this->offset,
129  'total' => $this->total_size,
130  );
131 
132  return $result;
133 
134  }//end getCurrentProgress()
135 
136 
137 }//end class
138 
139 
140 ?>