introduce UserInterface class, add simple parameter support for web and cli
[bdrem.git] / src / bdrem / UserInterface.php
diff --git a/src/bdrem/UserInterface.php b/src/bdrem/UserInterface.php
new file mode 100644 (file)
index 0000000..ffaa279
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+namespace bdrem;
+
+abstract class UserInterface
+{
+    public function run()
+    {
+        $cfg = new Config();
+        $cfg->load();
+        setlocale(LC_TIME, $cfg->locale);
+        $source = $cfg->loadSource();
+
+        $this->loadParameters($cfg);
+        $arEvents = $source->getEvents(
+            date('Y-m-d'), $cfg->daysBefore, $cfg->daysAfter
+        );
+        usort($arEvents, '\\bdrem\\Event::compare');
+        $this->render($arEvents);
+    }
+
+    protected function loadParameters($cfg)
+    {
+    }
+
+    abstract protected function render($arEvents);
+}
+?>
\ No newline at end of file