A framework-agnostic PHP notification package for sending messages across multiple channels. Works with Symfony, Laravel, or any native PHP project.
- Multiple notification channels: Email, Telegram, Slack
- Framework-agnostic — works with Symfony, Laravel, or plain PHP
- Built with clean OOP principles: interfaces, abstract classes, and inheritance
- Implements Factory pattern for easy channel creation
- Implements Command pattern for queuing and executing multiple notifications
- PSR-4 autoloading via Composer
- Implements Chain of Responsibility pattern for priority-based notification routing
- PHP >= 8.1
- Composer
composer require mhakkou/notifier<?php
require_once __DIR__ . '/vendor/autoload.php';
use Mhakkou\Notifier\Factory\NotificationFactory;
$notification = NotificationFactory::create(NotificationFactory::EMAIL_NOTIFICATION);
$notification->send('sender', 'recipient', 'subject', 'message');NotificationFactory::EMAIL_NOTIFICATION
NotificationFactory::TELEGRAM_NOTIFICATION
NotificationFactory::SLACK_NOTIFICATION<?php
require_once __DIR__ . '/vendor/autoload.php';
use Mhakkou\Notifier\Factory\NotificationFactory;
use Mhakkou\Notifier\Commands\SendNotificationCommand;
use Mhakkou\Notifier\Services\NotificationInvoker;
$invoker = new NotificationInvoker();
$invoker->addCommand(new SendNotificationCommand(
NotificationFactory::create(NotificationFactory::EMAIL_NOTIFICATION),
'sender', 'recipient', 'subject', 'message'
));
$invoker->addCommand(new SendNotificationCommand(
NotificationFactory::create(NotificationFactory::TELEGRAM_NOTIFICATION),
'sender', 'recipient', 'subject', 'message'
));
$invoker->addCommand(new SendNotificationCommand(
NotificationFactory::create(NotificationFactory::SLACK_NOTIFICATION),
'sender', 'recipient', 'subject', 'message'
));
$invoker->run(); // fires all three channels in sequencesrc/
├── Contracts/
│ └── NotificationInterface.php # Contract all channels must implement
├── Notifications/
│ ├── BaseNotification.php # Abstract base class with shared logic
│ ├── EmailNotification.php
│ ├── TelegramNotification.php
│ └── SlackNotification.php
├── Factory/
│ └── NotificationFactory.php # Factory for creating notification channels
├── Commands/
│ └── SendNotificationCommand.php # Command pattern implementation
├── Services/
| └── NotificationInvoker.php # Invoker that queues and runs commands
├── Handlers/
│ ├── BaseNotificationHandler.php
│ ├── SlackNotificationHandler.php
│ ├── TelegramNotificationHandler.php
│ └── EmailNotificationHandler.php
examples/
├── send_email.php
├── send_telegram.php
├── send_slack.php
└── send_multiple.php
└── chain_of_responsibility.php
Ready-to-run examples are available in the examples/ directory.
- Create a new class in
src/Notifications/extendingBaseNotification - Implement the
send()method - Register it in
NotificationFactory
$slack = new SlackNotificationHandler(); $telegram = new TelegramNotificationHandler(); $email = new EmailNotificationHandler();
$slack->setNext($telegram)->setNext($email); $slack->handle('high', 'sender', 'recipient', 'subject', 'message');
MIT © Hakkou Mouataz