/** * Send a notification message * * @param string $os * @return \Funkjedi\PushNotification\Message\MessageInterface */ public function create($os) { switch ($os) { case Device\Types::OS_ANDROID_C2DM: return new AndroidMessage(); case Device\Types::OS_ANDROID_GCM: $message = new AndroidMessage(); $message->setGCM(true); return $message; case Device\Types::OS_IOS: return new iOSMessage(); case Device\Types::OS_MAC: return new MacMessage(); case Device\Types::OS_BLACKBERRY: return new BlackberryMessage(); case Device\Types::OS_WINDOWSMOBILE: case Device\Types::OS_WINDOWSPHONE: return new WindowsphoneMessage(); } throw new \RuntimeException("OS type {$os} not supported"); }
public function testSetMessageIsReturnedInGetData() { $msg = new AndroidMessage(); $message = 'Test message'; $msg->setMessage($message); $this->assertEquals(array('message' => $message), $msg->getData()); $msg->setData(array('id' => 10)); $this->assertEquals(array('id' => 10, 'message' => $message), $msg->getData()); $msg->setData(array('message' => 'Other message')); $this->assertEquals(array('message' => 'Other message'), $msg->getData()); }
/** * Returns a message class based on the supplied os * * @param string $service The name of the service to return a message for * @throws \InvalidArgumentException * @return MessageInterface */ protected function getMessageClass($service) { switch ($service) { case "ios": return new PushMessage\iOSMessage(); case "c2dm": return new PushMessage\AndroidMessage(); case "gcm": $message = new PushMessage\AndroidMessage(); $message->setGCM(true); return $message; case "blackberry": return new PushMessage\BlackberryMessage(); case "mac": return new PushMessage\MacMessage(); case "windowsphone": return new PushMessage\WindowsphoneMessage(); default: throw new \InvalidArgumentException("Service '{$service}' not supported presently"); } }