public function shortMessage() { $ios = new Message(); $ios->setCustom(['data' => Lorem::text(2000)]); $android = new Message(); $android->setCustom(['data' => Lorem::text(4050)]); $android->setPlatforms([Message::PLATFORM_GCM]); return [[$ios], [$android]]; }
/** * @param null $text * @param bool $contentAvailable * @param array $options * @return Message */ public function getMessage($text = null, $contentAvailable = false, $options = []) { $message = new Message($text); $message->setBadge(0); if ($contentAvailable) { $message->setContentAvailable(true); } $message->setTtl(self::TTL_ONE_DAY); if (count($options)) { $message->setCustom($options); } return $message; }
private function getMessageForTweet($tweet) { $m = new Message($tweet['text']); $custom = ['i' => $tweet['id_str']]; //Check for links in the tweet foreach (['urls', 'media'] as $entity) { if (isset($tweet['entities']) && isset($tweet['entities'][$entity]) && isset($tweet['entities'][$entity][0])) { $entity = $tweet['entities'][$entity][0]; $custom['u'] = $entity['url']; //Remove the link from the text to save space $newText = trim(mb_substr($tweet['text'], 0, $entity['indices'][0], 'utf8') . ($this->linkPlaceholder ?: '') . mb_substr($tweet['text'], $entity['indices'][1], null, 'utf8')); if ($newText != '') { $m->setText($newText); } break; } } $m->setCustom($custom); $m->setTtl($this->gcmTtl); return $m; }
public function testAdmCustomData() { $message = new Message(); $message->setCustom(['simple' => 'Hello', 'complicated' => ['inner' => 'values']]); $string = (string) $message; $data = json_decode($string, true); $admData = json_decode($data['ADM'], true); $this->assertCount(2, $admData['data']); $this->assertArrayHasKey('simple', $admData['data']); $this->assertEquals('Hello', $admData['data']['simple']); $this->assertArrayHasKey('complicated_json', $admData['data']); $this->assertEquals(json_encode(['inner' => 'values']), $admData['data']['complicated_json']); }