Notifier

Build Status Code Climate Test Coverage Dependency Status HHVM Status

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:

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.5 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
     *
     * @return void
     */
    protected function notify($title, $message)
    {
        $this->execute("growlnotify -t '{$title}' -m '{$message}'");
    }

    /**
     * @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!');