1. Go to this page and download the library: Download azaharizaman/nexus-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/ */
azaharizaman / nexus-notifier example snippets
use Nexus\Notifier\Contracts\NotificationInterface;
use Nexus\Notifier\ValueObjects\Priority;
use Nexus\Notifier\ValueObjects\Category;
final class PayslipAvailableNotification implements NotificationInterface
{
public function __construct(
private readonly string $employeeName,
private readonly string $month,
private readonly string $downloadUrl
) {}
public function toEmail(): array
{
return [
'subject' => "Your {$this->month} Payslip is Ready",
'body' => "Hello {$this->employeeName}, your payslip for {$this->month} is now available. Download it here: {$this->downloadUrl}",
];
}
public function toSms(): string
{
return "Your {$this->month} payslip is ready. Download: {$this->downloadUrl}";
}
public function toPush(): array
{
return [
'title' => 'Payslip Available',
'body' => "Your {$this->month} payslip is ready",
'action' => $this->downloadUrl,
];
}
public function toInApp(): array
{
return [
'title' => 'Payslip Available',
'message' => "Your {$this->month} payslip is now available for download.",
'link' => $this->downloadUrl,
];
}
public function getPriority(): Priority
{
return Priority::Normal;
}
public function getCategory(): Category
{
return Category::Transactional;
}
}
use Nexus\Notifier\Contracts\NotificationManagerInterface;
final class PayrollManager
{
public function __construct(
private readonly NotificationManagerInterface $notifier
) {}
public function publishPayslip(string $employeeId): void
{
// Business logic to generate payslip...
$notification = new PayslipAvailableNotification(
employeeName: $employee->getName(),
month: 'January 2025',
downloadUrl: $payslipUrl
);
// Send via all preferred channels
$this->notifier->send($employee, $notification);
}
}
use Nexus\Notifier\Contracts\NotifiableInterface;
final class Employee implements NotifiableInterface
{
public function getNotificationEmail(): ?string
{
return $this->email;
}
public function getNotificationPhone(): ?string
{
return $this->mobilePhone;
}
public function getNotificationDeviceTokens(): array
{
return $this->deviceTokens ?? [];
}
public function getNotificationLocale(): string
{
return $this->preferredLocale ?? 'en';
}
public function getNotificationTimezone(): string
{
return $this->timezone ?? 'UTC';
}
}
// Only change binding in AppServiceProvider
$this->app->singleton(SmsChannelInterface::class, MessageBirdSmsChannel::class);
// No changes to Payroll, FieldService, or any other package!
// Simple, focused business logic
$this->notifier->send($user, new InvoiceReadyNotification($invoice));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.