mehr-als-nix / notifier
Desktop Notifier Library.
Installs: 62
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/mehr-als-nix/notifier
Requires
- php: >=5.6
Requires (Dev)
This package is auto-updated.
Last update: 2025-10-29 01:43:11 UTC
README
Desktop Notifications
Notifier acts as a wrapper for desktop notify applications on different operating systems.
Following notify wrappers are build in and would make checks to chose one of:
- notify-send (Linux)
- terminal-notifier (Mac)
- toast.exe (Windows) nels-o/toaster
Install via composer
Add a dependency on mehr-als-nix/notifier to your project's composer.json file.
Here is a minimal example of a manually created composer.json file that just defines a dependency on mehr-als-nix/notifier
{
    "require": {
        "mehr-als-nix/notifier": "~2"
    }
}
For PHP environments prior to version 5.6 use instead:
{
    "require": {
        "mehr-als-nix/notifier": "~1"
    }
}
Usage
Example:
   \MehrAlsNix\Notifier\Notify::getInstance()
       ->sendMessage('Notification', 'This is a desktop message!');
Extend
Custom class has to extend from \MehrAlsNix\Notifier\Notification
<?php
namespace \Custom\Notifier;
class GrowlNotifier extends \MehrAlsNix\Notifier\Notification
{
    /**
     * Notify with `growlnotify`.
     *
     * @param string $title
     * @param string $message
     * @param string $icon    optional
     *
     * @return void
     */
    protected function notify($title, $message, $icon = null)
    {
        $icon = is_string($icon) ? $icon : $this->icon;
        $this->execute("growlnotify -t '{$title}' -m '{$message}' --image '{$icon}'");
    }
    /**
     * @inheritdoc
     *
     * @return bool
     */
    public function isAvailable()
    {
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            return (bool) $this->execute('where.exe growlnotify');
        }
        
        return (bool) $this->execute('which growlnotify');
    }
}
And can then be used like:
    \MehrAlsNix\Notifier\Notify::getInstance('\Custom\Notifier\GrowlNotifier')
        ->sendMessage('Notification', 'This is a desktop message!');
or
    \MehrAlsNix\Notifier\Notify::getInstance('\Custom\Notifier\GrowlNotifier')
       ->setTitle('Notification')
       ->setMessage('This is a desktop message!')
       ->setIcon('/path/to/icon.png')
       ->send();