PhpDev.App
jolicode/JoliNotif

jolicode/JoliNotif

Stars: 1281

Forks: 85

Pull Requests: 56

Issues: 39

Watchers: 47

Last Updated: 2023-05-25 08:24:45

:computer: Send notifications to your desktop directly from your PHP script

License: MIT License

Languages: PHP, Makefile

http://jolicode.com/blog/desktop-notification-in-php

JoliNotif demo

Total Downloads Latest Stable Version Latest Unstable Version

About JoliNotif

JoliNotif is a cross-platform PHP library to display desktop notifications. It works on Linux, Windows or MacOS.

Requires PHP >= 7.4 (support for PHP 5 was available in version 1.x, for PHP 7.0 and 7.1 in version < 2.1.0, for PHP 7.2 and 7.3 in version < 2.4.0).

octicon-info mr-2" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true">Note
This library can not be used in a web context (FPM or equivalent). Use it in your CLI scripts or in a CRON

Installation

Use Composer to install JoliNotif in your project:

composer require "jolicode/jolinotif"

Usage

Use the NotifierFactory to create the correct Notifier (adapted to your OS), then use it to send your notification:

include __DIR__.'/vendor/autoload.php';

use Joli\JoliNotif\Notification;
use Joli\JoliNotif\NotifierFactory;

// Create a Notifier
$notifier = NotifierFactory::create();

// Create your notification
$notification =
    (new Notification())
    ->setTitle('Notification title')
    ->setBody('This is the body of your notification')
    ->setIcon(__DIR__.'/path/to/your/icon.png')
    ->addOption('subtitle', 'This is a subtitle') // Only works on macOS (AppleScriptNotifier)
    ->addOption('sound', 'Frog') // Only works on macOS (AppleScriptNotifier)
;

// Send it
$notifier->send($notification);

A shell executable is also provided to use JoliNotif from CLI:

jolinotif --title "Hello" --body "World"

Further documentation

Discover more by reading the docs:

You can see the current and past versions using one of the following:

And finally some meta documentation:

Credits

License

JoliNotif is licensed under the MIT License - see the LICENSE file for details.