mail sending
[bdrem.git] / src / bdrem / Cli.php
index 807f33679b1f0f7e13726e7f728e4a4c29e86471..21991610cf2dfcbe696dbe8a025d8f34f6a193d7 100644 (file)
@@ -1,25 +1,36 @@
 <?php
 namespace bdrem;
 
-class Cli
+class Cli extends UserInterface
 {
-    public function run()
+    protected function loadParameters()
     {
-        $cfg = new Config();
-        $cfg->load();
-        setlocale(LC_TIME, $cfg->locale);
-        $source = $cfg->loadSource();
+        $params = $GLOBALS['argv'];
+        array_shift($params);
+        $storeInto = null;
+        foreach ($params as $param) {
+            if ($storeInto !== null) {
+                $this->config->$storeInto = (int)$param;
+                $storeInto = null;
+                continue;
+            }
 
-        $arEvents = $source->getEvents(
-            date('Y-m-d'), $cfg->daysBefore, $cfg->daysAfter
-        );
-        usort($arEvents, '\\bdrem\\Event::compare');
-        $this->render($arEvents);
+            if ($param == '--days-after' || $param == '-a') {
+                $storeInto = 'daysAfter';
+                continue;
+            } else if ($param == '--days-before' || $param == '-b') {
+                $storeInto = 'daysBefore';
+                continue;
+            }
+            $storeInto = null;
+        }
     }
 
-    public function render($arEvents)
+    protected function render($arEvents)
     {
-        $r = new Renderer_Console();
+        $r = new Renderer_Mail();
+        $r->config = $this->config;
+        $r->ansi = true;
         echo $r->render($arEvents);
     }
 }