/** * Sends a message to a device, identified by * the OS and the supplied device token * * @param \Funkjedi\PushNotification\Message\MessageInterface $message * @throws \RuntimeException * @return bool */ public function send(MessageInterface $message) { if (!isset($this->handlers[$message->getTargetOS()])) { throw new \RuntimeException("OS type {$message->getTargetOS()} not supported"); } return $this->handlers[$message->getTargetOS()]->send($message); }
/** * Gets hander identified by the OS and the supplied device token * * @param \Funkjedi\PushNotification\Message\MessageInterface $message * @return \Funkjedi\PushNotification\Service\Os\OSNotificationServiceInterface */ protected function getDriver(MessageInterface $message) { $os = $message->getTargetOS(); switch ($os) { case Device\Types::OS_ANDROID_C2DM: return new AndroidNotification(@$this->config['android']['c2dm']['username'], @$this->config['android']['c2dm']['password'], @$this->config['android']['c2dm']['source']); case Device\Types::OS_ANDROID_GCM: return new AndroidGCMNotification(@$this->config['android']['gcm']['api_key'], @$this->config['android']['gcm']['use_multi_curl']); case Device\Types::OS_IOS: case Device\Types::OS_MAC: return new AppleNotification(@$this->config[$os]['sandbox'], @$this->config[$os]['pem'], @$this->config[$os]['passphrase'], @$this->config[$os]['json_unescaped_unicode']); case Device\Types::OS_BLACKBERRY: return new BlackberryNotification(@$this->config['blackberry']['evaluation'], @$this->config['blackberry']['app_id'], @$this->config['blackberry']['password']); case Device\Types::OS_WINDOWSMOBILE: case Device\Types::OS_WINDOWSPHONE: return new MicrosoftNotification(); } throw new \RuntimeException("OS type {$os} not supported"); }