/** * @param null $connection * @return bool * @throws \Exception */ public function send($connection = null) { $notifiers = Config::get('notifiers'); if (!is_null($connection) && array_has($notifiers, $connection)) { $notifiers = array_only($notifiers, [$connection]); } $factory = new NotifyMeFactory(); $successes = 0; foreach ($notifiers as $notifier) { if ($this->sender) { array_set($notifier, 'from', $this->sender); } $service = $factory->make($notifier); switch (array_get($notifier, 'driver')) { case 'hipchat': $response = $service->notify(array_get($notifier, 'room'), $this->message); break; default: throw new \Exception("Driver not yet supported."); } if ($response->isSent()) { $successes++; } else { throw new \Exception($response->message()); } } return $successes == count($notifiers); }
/** * @param $arguments */ protected function triggerListeners($arguments) { $listeners = Config::get('listeners'); foreach (array_get($listeners, class_basename($this), []) as $listener) { $instance = new $listener(); $instance->catched($this); } }
/** * Sets up the a daemonized connection * * @throws \Exception */ public static function run() { global $argv; $config = Config::get(); if (count($argv) > 1 && array_get($config, "teamspeak.{$argv[1]}")) { $connection = array_get($config, "teamspeak.{$argv[1]}"); } elseif (count(array_get($config, 'teamspeak', [])) === 1) { $connection = array_shift(array_get($config, 'teamspeak')); } else { throw new \Exception("No connection found for Teamspeak"); } (new Daemon($connection, static::config()))->daemonize(); }