jolicode/jolinotif
Cross-platform PHP library for sending desktop notifications from CLI scripts or cron jobs on Linux, macOS, Windows, and WSL. Create notifications with title, body, icon, and OS-specific options, or use the bundled jolinotif CLI command.
JoliNotif provides a DefaultNotifier class which is the main entrypoint of
the library. It's main goal is to provide a simple way to send a desktop
notification without having to care about the platform you're running on. It
will work whether you're on Linux, Windows or macOS.
use Joli\JoliNotif\DefaultNotifier;
use Joli\JoliNotif\Notification;
$notifier = new DefaultNotifier();
$notifier->send(new Notification());
And you're done!
Internally, the notifier will use each driver's priority to determine the best one available on your system. For example, some driver have a low priority because they don't support some notification options. So if a better driver is available, it will be used.
[!NOTE] In case no driver is supported or if an error happens during notification sending, the send method will return false.
[!TIP] If you want to log when an error happens or if no driver is supported, you can also pass an instance of
Psr\Log\LoggerInterfaceas the first parameter of theDefaultNotifier's constructor.
Create a notification is as simple as instantiating a Notification and
setting the option you want to use:
use Joli\JoliNotif\Notification;
$notification =
(new Notification())
->setBody('The notification body')
->setTitle('The notification title')
->addOption('subtitle', 'This is a subtitle') // Only works on macOS (AppleScriptDriver)
->addOption('sound', 'Frog') // Only works on macOS (AppleScriptDriver & TerminalNotifierDriver)
->addOption('url', 'https://google.com') // Only works on macOS (TerminalNotifierDriver)
;
As you can see, the notification class provides a fluent API.
Previous pages:
How can I help you explore Laravel packages today?