aboutsummaryrefslogtreecommitdiff
path: root/src/callnotifier/Source/File.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/callnotifier/Source/File.php')
-rw-r--r--src/callnotifier/Source/File.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/callnotifier/Source/File.php b/src/callnotifier/Source/File.php
new file mode 100644
index 0000000..c358397
--- /dev/null
+++ b/src/callnotifier/Source/File.php
@@ -0,0 +1,34 @@
+<?php
+namespace callnotifier;
+
+class Source_File
+{
+ public function __construct($config, $handler)
+ {
+ $this->config = $config;
+ $this->handler = $handler;
+ }
+
+ public function run()
+ {
+ $file = $this->config->replayFile;
+ if (!file_exists($file)) {
+ throw new Exception('Replay file does not exist');
+ }
+
+ $handle = fopen($file, 'r');
+ if (!$handle) {
+ throw new Exception('Cannot open replay file for reading');
+ }
+
+ while (($line = fgets($handle, 4096)) !== false) {
+ $this->handler->handle($line);
+ }
+ if (!feof($handle)) {
+ throw new Exception('unexpected fgets() fail');
+ }
+ fclose($handle);
+ }
+}
+
+?>