4 abstract class UserInterface
10 $this->config = new Config();
11 $this->config->load();
12 $this->config->date = date('Y-m-d');
13 setlocale(LC_TIME, $this->config->locale);
14 $source = $this->config->loadSource();
16 $parser = $this->loadParameters();
17 $this->parseParameters($parser);
19 $arEvents = $source->getEvents(
21 $this->config->daysPrev, $this->config->daysNext
23 usort($arEvents, '\\bdrem\\Event::compare');
24 $this->render($arEvents);
27 protected function loadParameters()
29 $parser = new \Console_CommandLine();
30 $parser->description = 'Birthday reminder';
31 $parser->version = '0.1.0';
37 'long_name' => '--days-next',
38 'description' => 'Show NUM days after date',
40 'action' => 'StoreInt',
41 'default' => $this->config->daysNext,
48 'long_name' => '--previous',
49 'description' => 'Show NUM days before date',
51 'action' => 'StoreInt',
52 'default' => $this->config->daysPrev,
59 'long_name' => '--renderer',
60 'description' => 'Output mode',
61 'action' => 'StoreString',
68 'default' => 'console',
69 'add_list_option' => true,
76 'long_name' => '--quiet',
77 'description' => "Don't print status messages to stdout",
78 'action' => 'StoreTrue'
84 protected function parseParameters($parser)
87 $result = $parser->parse();
88 // do something with the result object
89 $this->config->daysNext = $result->options['daysNext'];
90 $this->config->daysPrev = $result->options['daysPrev'];
91 $this->config->renderer = $result->options['renderer'];
92 $this->config->quiet = $result->options['quiet'];
93 } catch (\Exception $exc) {
94 $this->preRenderParameterError();
95 $parser->displayError($exc->getMessage());
99 protected function render($arEvents)
101 $r = $this->getRenderer();
102 $r->config = $this->config;
103 $r->renderAndOutput($arEvents);
106 protected function getRenderer()
108 $renderer = ucfirst($this->config->renderer);
109 if ($renderer == 'Htmltable') {
110 $renderer = 'HtmlTable';
112 $class = '\\bdrem\\Renderer_' . $renderer;
116 protected function preRenderParameterError()