dumping network data is possible now
[auerswald-callnotifier.git] / src / callnotifier / Source / File.php
1 <?php
2 namespace callnotifier;
3
4 class Source_File
5 {
6     public function __construct($config, $handler)
7     {
8         $this->config  = $config;
9         $this->handler = $handler;
10     }
11
12     public function run()
13     {
14         $file = $this->config->replayFile;
15         if (!file_exists($file)) {
16             throw new Exception('Replay file does not exist');
17         }
18
19         $handle = fopen($file, 'r');
20         if (!$handle) {
21             throw new Exception('Cannot open replay file for reading');
22         }
23
24         while (($line = fgets($handle, 4096)) !== false) {
25             $this->handler->handle($line);
26         }
27         if (!feof($handle)) {
28             throw new Exception('unexpected fgets() fail');
29         }
30         fclose($handle);
31     }
32 }
33
34 ?>