PHP code example of symfony / novu-notifier
1. Go to this page and download the library: Download symfony/novu-notifier library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
symfony / novu-notifier example snippets
class NovuNotification extends Notification implements PushNotificationInterface
{
/** @var array<string, mixed> */
private array $overrides = [];
/** @var array<string, mixed> */
private array $context = [];
/**
* @param array<string, mixed> $overrides
*/
public function setOverrides(array $overrides): void
{
$this->overrides = $overrides;
}
/**
* @param array<string, mixed> $context
*/
public function setContext(array $context): void
{
$this->context = $context;
}
public function asPushMessage(
NovuSubscriberRecipient|RecipientInterface $recipient,
?string $transport = null,
): ?PushMessage {
return new PushMessage(
$this->getSubject(),
$this->getContent(),
new NovuOptions(
$recipient->getSubscriberId(),
$recipient->getFirstName(),
$recipient->getLastName(),
$recipient->getEmail(),
$recipient->getPhone(),
$recipient->getAvatar(),
$recipient->getLocale(),
$this->overrides,
[],
$this->context,
),
);
}
}
$notification = new NovuNotification;
$notification->subject('test');
$notification->channels(['push']);
$notification->content(
json_encode(
[
'param1' => 'Lorum Ipsum',
]
)
);
$notification->setOverrides([
'email' => [
'from' => '[email protected] ',
'senderName' => 'No-Reply',
],
]);
$notification->setContext([
'tenant' => 'tenant-id',
'app' => 'app-id',
]);
$this->notifier->send(
$notification,
new NovuSubscriberRecipient(
"123",
'Wouter',
'van der Loop',
'[email protected] ',
null,
null,
null,
),
);