2 namespace callnotifier;
9 public function __construct()
16 $config = new Config();
18 $result = $this->cliParser->parse();
19 } catch (\Exception $exc) {
20 $this->cliParser->displayError($exc->getMessage());
23 $this->fillConfig($config, $result);
26 if ($result->options['debug'] || $result->options['debugEdss1']) {
27 $debugLogger = new Logger_Debug();
28 $log->addLogger($debugLogger, '*');
29 if ($result->options['debugEdss1']) {
30 $debugLogger->edss1MsgOnly = true;
34 $callMonitor = new CallMonitor($config, $log);
36 $configFile = $this->getConfigFile();
37 if ($configFile !== null) {
41 $handler = new MessageHandler($config, $log, $callMonitor);
43 if ($config->replayFile !== null) {
44 $sourceClass = 'callnotifier\Source_File';
46 $sourceClass = 'callnotifier\Source_Remote';
50 $source = new $sourceClass($config, $handler);
52 } catch (\Exception $e) {
53 $msg = 'Callnotifier error!' . "\n"
54 . 'Code: ' . $e->getCode() . "\n"
55 . 'Message: ' . $e->getMessage() . "\n";
56 file_put_contents('php://stderr', $msg);
61 public function setupCli()
63 $p = new \Console_CommandLine();
64 $p->description = 'Notifies about incoming calls on an Auerswald COMpact 3000';
65 $p->version = '0.0.1';
71 'long_name' => '--host',
72 'description' => 'IP of COMpact 3000',
74 'action' => 'StoreString'
81 'long_name' => '--dump',
82 'description' => 'Dump messages into file for later replay',
83 'help_name' => 'FILE',
84 'action' => 'StoreString'
90 'long_name' => '--replay',
91 'description' => "Replay messages from file instead from network",
92 'help_name' => 'FILE',
93 'action' => 'StoreString'
100 'short_name' => '-d',
101 'long_name' => '--debug',
102 'description' => "Debug mode: Echo all received messages and events",
103 'action' => 'StoreTrue'
109 'short_name' => '-e',
110 'long_name' => '--debug-edss1',
111 'description' => "Debug mode: Show EDSS1 messages only",
112 'action' => 'StoreTrue'
116 $this->cliParser = $p;
119 protected function fillConfig($config, $result)
121 $config->setIfNotEmpty('host', $result->options['host']);
122 $config->setIfNotEmpty('dumpFile', $result->options['dumpFile']);
123 $config->setIfNotEmpty('replayFile', $result->options['replayFile']);
127 * Finds the path to the configuration file.
129 * The following locations are tried:
130 * - Git checkout: data/callnotifier.config.php
131 * - ~/.config/callnotifier.config.php
132 * - /etc/callnotifier.config.php
134 * @return string Full path of config file or NULL if no file found
136 protected function getConfigFile()
138 if (basename(dirname(__DIR__)) == 'src'
139 && file_exists(__DIR__ . '/../../data/callnotifier.config.php')
141 return __DIR__ . '/../../data/callnotifier.config.php';
144 if (isset($_ENV['HOME'])) {
145 $file = $_ENV['HOME'] . '/.config/callnotifier.config.php';
146 if (file_exists($file)) {
151 $file = '/etc/callnotifier.config.php';
152 if (file_exists($file)) {