本文整理汇总了PHP中Notification::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Notification::getContent方法的具体用法?PHP Notification::getContent怎么用?PHP Notification::getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notification
的用法示例。
在下文中一共展示了Notification::getContent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetContent
/**
* @covers Notification::getContent
* @todo Implement testGetContent().
*/
public function testGetContent()
{
$content = "Conversation content";
$this->notification->setContent($content);
$actual = $this->notification->getContent();
$this->assertEquals($content, $actual);
}
示例2: send
/**
* Send the given notification with Apple Push Notification Service Server.
*
* @param Notification $notification the notification to send
* @return boolean true on success, false if there was an error.
*/
public function send($notification)
{
$config = Config::getInstance();
$appRoot = $config->getString('appRootDir');
// Instanciate a new ApnsPHP_Push object, with the provider certificate
$push = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION, $appRoot . $config->getString('monitoring/notification/push/providerCertificateDir'));
// Set custom logger
$push->setLogger(new ApnsPHP_Log_Fruition());
// Set the Provider Certificate passphrase
$push->setProviderCertificatePassphrase($config->getString('monitoring/notification/push/passphrase'));
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority($appRoot . $config->getString('monitoring/notification/push/rootCertificateAuthorityDir'));
// Get recipient list. If no registration id (user did not connect to the
// mobile app, we stop the process
$stringRecipients = $notification->getRecipient();
if (empty($stringRecipients)) {
Logger::info("No registration id was found. The notification is not sent.");
return false;
}
// Connect to the Apple Push Notification Service
$push->connect();
// Create a message for each device
$message = new ApnsPHP_Message();
$message->setText($notification->getContent());
$message->setSound();
$message->setExpiry(30);
// 60 seconds
$recipientList = explode(",", $notification->getRecipient());
foreach ($recipientList as $registrationId) {
$message->addRecipient($registrationId);
}
// Add the message to the message queue
$push->add($message);
// Send all messages in the message queue
$push->send();
// Disconnect from the Apple Push Notification Service
$push->disconnect();
// Examine the error message container.
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
foreach ($aErrorQueue as $error) {
foreach ($error['ERRORS'] as $err) {
//For statusCode = 8, which is Invalid Token, we delete the token.
if ($err['statusCode'] == self::INVALID_TOKEN) {
if ($this->handlerErrorCallBack) {
$token = $error['MESSAGE']->getRecipient();
call_user_func($this->handlerErrorCallBack, $token);
}
}
Logger::error("Sending push notification failed. Error code: " . $err['statusCode'] . ". Message: " . $err['statusMessage']);
}
}
return false;
}
//If success
Logger::info("Notification sent with device token " . $notification->getRecipient());
return true;
}
示例3: getContent
/**
* Get the final content of this notification, after evaluating the PHP
* code and substituting variables.
*
* @param boolean $reprocess if true, content will be recomputed. Otherwise
* template will be processed only the first time.
* @return String the content
*/
public function getContent($reprocess = false)
{
if (parent::getContent() === null || $reprocess) {
// First, process the template to execute any PHP code.
$preoceesedMessage = $this->processTemplate("?>" . $this->templateContent);
// Take the result and perform substitution of variables
$message = new LocalizedString($preoceesedMessage);
foreach ($this->attributes as $key => $value) {
$message->set($key, $value);
}
parent::setContent($message->__toString());
}
return parent::getContent();
}