4 abstract class UserInterface
11 $this->config = new Config();
12 $this->config->load();
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);
25 } catch (\Exception $e) {
26 $this->preRenderParameterError();
27 echo 'Exception: ' . $e->getCode() . ' ' . $e->getMessage() . "\n";
32 protected function loadParameters()
34 $parser = new \Console_CommandLine();
35 $parser->description = 'Birthday reminder';
36 $parser->version = '0.1.0';
42 'long_name' => '--days-next',
43 'description' => 'Show NUM days after date',
45 'action' => 'StoreInt',
46 'default' => $this->config->daysNext,
53 'long_name' => '--previous',
54 'description' => 'Show NUM days before date',
56 'action' => 'StoreInt',
57 'default' => $this->config->daysPrev,
64 'long_name' => '--renderer',
65 'description' => 'Output mode',
66 'action' => 'StoreString',
73 'default' => 'console',
74 'add_list_option' => true,
81 'long_name' => '--stoponempty',
82 'description' => 'Output nothing when list is empty',
83 'action' => 'StoreTrue',
91 'long_name' => '--date',
92 'description' => 'Date to show events for',
93 'action' => 'StoreString'
100 'long_name' => '--quiet',
101 'description' => "Don't print status messages to stdout",
102 'action' => 'StoreTrue'
108 protected function parseParameters($parser)
111 $result = $parser->parse();
112 // do something with the result object
113 $this->config->daysNext = $result->options['daysNext'];
114 $this->config->daysPrev = $result->options['daysPrev'];
115 $this->config->renderer = $result->options['renderer'];
116 $this->config->quiet = $result->options['quiet'];
117 $this->config->stopOnEmpty = $result->options['stopOnEmpty'];
118 $this->config->setDate($result->options['date']);
119 } catch (\Exception $exc) {
120 $this->preRenderParameterError();
121 $parser->displayError($exc->getMessage());
125 protected function render($arEvents)
127 $r = $this->getRenderer();
128 $r->config = $this->config;
130 if ($this->config->stopOnEmpty && count($arEvents) == 0) {
131 $r->handleStopOnEmpty();
134 $r->renderAndOutput($arEvents);
137 protected function getRenderer()
139 $renderer = ucfirst($this->config->renderer);
140 if ($renderer == 'Htmltable') {
141 $renderer = 'HtmlTable';
143 $class = '\\bdrem\\Renderer_' . $renderer;
147 protected function preRenderParameterError()