1. Introduction

Net_Growl logo

Net_Growl is a PHP Library that makes it possible to easily send a notification from your PHP script to Growl.

Two different protocols may be used: the basic UDP (compatible with all platforms), and the new one GNTP (compatible only with Windows).

The major version 2 is a full rewrites to PHP5, that used exceptions to raise errors.

PHP4 versions are no more supported. If you want one of them, you should consider to have a look on these solutions :

Caution I recommand to migrate to PHP5, because I don’t gave anymore support for PHP4 versions

This manual documents the final stable version 2.0.0

2. Features

  • Register your PHP application in Growl.

  • Let Growl know what kind of notifications to expect.

  • Notify Growl.

  • Set a maximum number of notifications to be displayed (beware the loops !).

  • Use either UDP or GNTP adapter for communication.

  • Encrypt data to secure communication.

3. System Requirements

Mac OSX platform :
  • Growl requires Mac OS X 10.5 or higher.

Windows platform :
  • Growl for Windows is a Windows-compatible version of Growl, a notification system for Mac OS X.

Mandatory resources :
  • PHP 5.2.0 or newer

  • hash extension requires no external libraries and is enabled by default as of PHP 5.1.2

Optional resources :
  • mcrypt extension when using GNTP adapter and encryt feature

4. Installing Net_Growl

Note The current version of Net_Growl requires PHP 5.2.0 or newer to run. If you don’t already have an up-to-date version of PHP installed it can be downloaded from the official PHP website http://www.php.net/.

4.1. Using PEAR installer

Net_Growl should be installed using the PEAR Installer. This installer is the backbone of PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0.

The PEAR channel (__uri) that is used to distribute Net_Growl is included by default with with the local PEAR environment.

You just have to run this command :

pear install http://growl.laurent-laville.org/bin/Net_Growl-X.Y.Z.tgz

Replace X.Y.Z by version you want to install.

4.2. Install manually

Do the following:

  1. Download a release archive from http://growl.laurent-laville.org/bin/

  2. Extract it to a directory that is listed in the include_path of your php.ini configuration file

5. Getting Started with Net_Growl

5.1. Register your application

Before to send any notification, you should register your application to Growl.

Consider an application as a group of elements included :

  • a unique name to identify the application (required)

  • 1 icon to represent visually your application (optional - used default growl icon if missing)

  • a list of notification types that will receive future messages (required - an empty list does not have sense)

Caution Do not register each time you send a new notification. It’s unnecessary.
Tip Net_Growl will register your application at first notification send, if it was not implicitly called before with Net_Growl::register().
Example 1: Register your first application
<?php
require_once 'Net/Growl.php';

$notifications = array(
    'GROWL_NOTIFY_STATUS' => array(
        'display' => 'Status',
    ),
    'GROWL_NOTIFY_PHPERROR' => array(
        'display' => 'Error-Log'
    )
);
$appName  = 'PHP App Example using GNTP';
$password = 'mamasam';
$options  = array(
    'host'     => '192.168.1.2',
    'protocol' => 'tcp',
    'port'     => Net_Growl::GNTP_PORT,
    'timeout'  => 15,
);

try {
    $growl = Net_Growl::singleton($appName, $notifications, $password, $options);
    $growl->register();

} catch (Net_Growl_Exception $e) {
    echo 'Caught Growl exception: ' . $e->getMessage() . PHP_EOL;
?>

Previously, we have seen how to register an application with all definitions given by the Net_Growl class constructor. Now we will see an alternative solution using a Net_Growl_Application object.

Example 2: Register with a Net_Growl_Application object
<?php
require_once 'Net/Growl.php';

$notifications = array(
    'GROWL_NOTIFY_PHPERROR'
);
$appName  = 'PHP App Example using GNTP';
$password = 'mamasam';

$app = new Net_Growl_Application(
    $appName,
    $notifications,
    $password
);
$options = array(
    'host'     => '192.168.1.2',
    'protocol' => 'tcp',
    'port'     => Net_Growl::GNTP_PORT
);

$growl = Net_Growl::singleton($app, null, null, $options);
$growl->register();
?>

5.2. Notify a simple basic message

Warning
Distinct UDP and GNTP communication

Default options will used the basic UDP protocol on port 9887.

If you want to use the new GNTP, you should specify options protocol (= tcp) and port (= 23053)

See singleton method, and options parameter (#4).

We will reused the source code presented in register application feature, and used tip to auto-register application at first notification call.

<?php
require_once 'Net/Growl.php';

$notifications = array(
    'GROWL_NOTIFY_STATUS' => array(
        'display' => 'Status',
    ),
    'GROWL_NOTIFY_PHPERROR' => array(
        'display' => 'Error-Log'
    )
);
$appName  = 'PHP App Example using GNTP';
$password = 'mamasam';
$options  = array(
    'host'     => '192.168.1.2',
    'protocol' => 'tcp',
    'port'     => Net_Growl::GNTP_PORT,
    'timeout'  => 15,
);

try {
    $growl = Net_Growl::singleton($appName, $notifications, $password, $options);

    $name        = 'GROWL_NOTIFY_STATUS';
    $title       = 'Congratulation';
    $description = 'Congratulation! You are successfull install PHP/NetGrowl.';
    $options     = array();
    $growl->notify($name, $title, $description, $options);

} catch (Net_Growl_Exception $e) {
    echo 'Caught Growl exception: ' . $e->getMessage() . PHP_EOL;
?>

We have defined two notifications type
[GROWL_NOTIFY_STATUS and GROWL_NOTIFY_PHPERROR]
when register application on getting a Growl instance. But we use only one of them to send our basic Congratulation message.

5.3. Notify different message types

You can define as much notification types as you want, depending of your need. For example, Gmail Growl sets 3 types

  • New Mail

  • state

  • New Version

Here, in our example, we will set 2 notification types

  • Status (GROWL_NOTIFY_STATUS)

  • Error-Log (GROWL_NOTIFY_PHPERROR)

and send messages on both channels.

Here are the full script, we will explain just after :

<?php
require_once 'Net/Growl.php';

$notifications = array(
    'GROWL_NOTIFY_STATUS' => array(
        'display' => 'Status',
    ),
    'GROWL_NOTIFY_PHPERROR' => array(
        'icon'    => 'http://www.laurent-laville.org/growl/images/firephp.png',
        'display' => 'Error-Log'
    )
);
$appName  = 'PHP App Example using GNTP';
$password = 'mamasam';
$options  = array(
    'host'     => '192.168.1.2',
    'protocol' => 'tcp',
    'port'     => Net_Growl::GNTP_PORT,
    'timeout'  => 15,
    'AppIcon'  => 'http://www.laurent-laville.org/growl/images/Help.png',
);

try {
    $growl = Net_Growl::singleton($appName, $notifications, $password, $options);

    $name        = 'GROWL_NOTIFY_STATUS';
    $title       = 'Congratulation';
    $description = 'Congratulation! You are successfull install PHP/NetGrowl.';
    $options     = array();
    $growl->notify($name, $title, $description, $options);

    $name        = GROWL_NOTIFY_PHPERROR;
    $title       = 'PHP Error';
    $description = 'You have a new PHP error in your script P at line N';
    $options     = array(
        'priority' => Net_Growl::PRIORITY_HIGH,
    );
    $growl->notify($name, $title, $description, $options);

    $name        = GROWL_NOTIFY_STATUS;
    $title       = 'Welcome';
    $description = "Welcome in PHP/GNTP world ! \n"
                 . "New GNTP protocol add icon support.";
    $options     = array(
        'icon'   => 'http://www.laurent-laville.org/growl/images/unknown.png',
        'sticky' => false,
    );
    $growl->notify($name, $title, $description, $options);

} catch (Net_Growl_Exception $e) {
    echo 'Caught Growl exception: ' . $e->getMessage() . PHP_EOL;
?>

First message notified by code below

    $name        = 'GROWL_NOTIFY_STATUS';
    $title       = 'Congratulation';
    $description = 'Congratulation! You are successfull install PHP/NetGrowl.';
    $options     = array();
    $growl->notify($name, $title, $description, $options);

will show the Toast notification (only on first script run)

Net_Growl Register

Followed by

Notify Status 1

Second message sent over the other channel (notification type) on a highest priority

    $name        = GROWL_NOTIFY_PHPERROR;
    $title       = 'PHP Error';
    $description = 'You have a new PHP error in your script P at line N';
    $options     = array(
        'priority' => Net_Growl::PRIORITY_HIGH,
    );
    $growl->notify($name, $title, $description, $options);

will show this Toast notification

Notify PHP Error

And finally the third and last message with default application icon
[http://www.laurent-laville.org/growl/images/Help.png (AppIcon option of singleton method)]
because resource http://www.laurent-laville.org/growl/images/unknown.png does not exist.

    $name        = GROWL_NOTIFY_STATUS;
    $title       = 'Welcome';
    $description = "Welcome in PHP/GNTP world ! \n"
                 . "New GNTP protocol add icon support.";
    $options     = array(
        'icon'   => 'http://www.laurent-laville.org/growl/images/unknown.png',
        'sticky' => true,
    );
    $growl->notify($name, $title, $description, $options);

will show this other one Toast notification

Notify Status 2

6. Secure your communication

Warning This chapter is only for reader that use the GNTP adapter. Even if UDP is binary format protocol, it shouldn’t be considered as secure.

GNTP is a MIME like format, contents are sent as readable plain text. You should think to use either :

  • a HTTPS secure channel

  • encrypt your data on a basic HTTP channel

We will see now, how to encrypt your data and what formats are supported.

The authorization of messages is accomplished by passing key information that proves that the sending application knows a shared secret with the notification system, namely a password. Users that want to authorize applications must share with them a password that will be used for both authorization and encryption.

Note By default, authorization is not required for requests orginating on the local machine.
Table 1. The supported hashing algorithms
Hash Features

MD5

128-bit, 16 byte, 32 character length when hex encoded

SHA1

160-bit, 20 byte, 40 character length when hex encoded

SHA256

256-bit, 32 byte, 64 character length when hex encoded

SHA512

512-bit, 64 byte, 128 character length when hex encoded

Table 2. The supported encryption algorithms
Hash Features

NONE

No encryption; messages are sent in plain text

AES

key length: 24 bytes (192 bit), block size: 16 byte (128 bit), iv size: 16 byte (128 bit)

DES

key length: 8 bytes (64 bit), block size: 8 byte (64 bit), iv size: 8 byte (64 bit)

3DES

key length: 24 bytes (192 bit), block size: 8 byte (64 bit), iv size: 8 byte (64 bit)

Note All encryption algorithms should use a block mode of CBC (Cipher Block Chaining) and PKCS5 (PKCS7) padding.
Important It is important to keep in mind that some encryption algorithms require keys that are longer than can be generated by some hashing algorithms. As such, not all hash/encryption combinations are valid (ex: MD5 hash produces a 16 byte result, but AES encryption requires a 24-byte key).
Table 3. Hash and Encryption algorithms compatibilities
Encryption Hash

AES

SHA256, SHA512

DES

MD5, SHA1, SHA256, SHA512

3DES

SHA256, SHA512

To encrypt your data, its very easy. You have just to specify in options of Net_Growl::singleton method :

Example 3: encrypted messages with AES/SHA256
<?php
require_once 'Net/Growl.php';

$notifications = array(
    'GROWL_NOTIFY_PHPERROR'
);
$appName  = 'PHP App Example using GNTP/encrypt AES';
$password = 'mamasam';

$app = new Net_Growl_Application(
    $appName,
    $notifications,
    $password
);
$options = array(
    'host'     => '192.168.1.2',
    'protocol' => 'tcp',
    'port'     => Net_Growl::GNTP_PORT,
    'timeout'  => 10,
    'encryptionAlgorithm'   => 'AES',
    'passwordHashAlgorithm' => 'SHA256',
);

try {
    $growl = Net_Growl::singleton($app, null, null, $options);
    $growl->register();

    $title       = 'Welcome in PHP/GNTP world';
    $description = "New GNTP protocol support 3 encryption algorithms ! \n"
                 . "DES, 3DES, AES with 4 hash algorithm \n"
                 . "MD5, SHA1, SHA256, SHA512.";
    $options     = array(
        'sticky' => true,
    );
    $growl->notify($name, $title, $description, $options);

} catch (Net_Growl_Exception $e) {
    echo 'Growl exception: ' . $e->getMessage() . PHP_EOL;
}
?>

7. Frequently Asked Questions

7.1. Troubleshooting

  1. The response times are slow

    You can reduced timeout period on a stream (socket) to connect/read. Default is 30 secondes, like php.ini default_socket_timeout directive.

    Example 4: Set timetout to 15 secondes
    <?php
    require_once 'Net/Growl.php';
    
    $notifications = array(
        'GROWL_NOTIFY_PHPERROR'
    );
    $appName  = 'PHP App Example using GNTP';
    $password = 'mamasam';
    
    $app = new Net_Growl_Application(
        $appName,
        $notifications,
        $password
    );
    $options = array(
        'host'     => '192.168.1.2',
        'protocol' => 'tcp',
        'port'     => Net_Growl::GNTP_PORT,
        'timeout'  => 15
    );
    
    $growl = Net_Growl::singleton($app, null, null, $options);
    $growl->register();
    ?>
    Tip You can also suppress timeout by setting value to zero.
  2. Notifications are not displayed

    • Are you sure Growl is running (not stopped or paused) ?

    • Check if your application and the notification type used is well registered

    • If your application is well registered, check if notifications display are enabled

    • Password provided by your application is probably unknown of Growl client (see Password Manager on Security Tab)

    • Check if your code produces error/exceptions.

      Example 5: Catch errors with a try catch
      <?php
      require_once 'Net/Growl.php';
      
      $notifications = array(
          'GROWL_NOTIFY_PHPERROR'
      );
      $appName  = 'PHP App Example using GNTP';
      $password = 'mamasam';
      $options  = array(
          'host'     => '192.168.1.2',
          'protocol' => 'tcp',
          'port'     => Net_Growl::GNTP_PORT
      );
      
      try {
          $growl = Net_Growl::singleton($appName, $notifications, $password, $options);
          $growl->register();
      
      } catch (Net_Growl_Exception $e) {
          echo 'Caught Growl exception: ' . $e->getMessage() . PHP_EOL;
      }
      ?>
      Important All errors produced by Net_Growl raise a Net_Growl_Exception
  3. Net_Growl is not really verbose

    To known what MIME messages are sent and received from Growl, activate the verbose mode. Give a valid path to a filename on debug option.

    Example 6: Activate the debug mode
    <?php
    require_once 'Net/Growl.php';
    
    $notifications = array(
        'GROWL_NOTIFY_PHPERROR'
    );
    $appName  = 'PHP App Example using GNTP';
    $password = 'mamasam';
    $options  = array(
        'host'     => '192.168.1.2',
        'protocol' => 'tcp',
        'port'     => Net_Growl::GNTP_PORT,
        'debug'    => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'netgrowl.log'
    );
    
    try {
        $growl = Net_Growl::singleton($appName, $notifications, $password, $options);
        $growl->register();
    
    } catch (Net_Growl_Exception $e) {
        echo 'Caught Growl exception: ' . $e->getMessage() . PHP_EOL;
    }
    ?>
  4. My favorite application icons are not shown

    • URL given are not valid or not reachable

    • URL are good but resources are invalid images

      Note If you give URL/resource that are not valid, Net_Growl will use default icon returns by Net_Growl::getDefaultGrowlIcon method.
  5. How to detect error with new version 2.1

    GNTP specialized response are now returned with version 2.1.0 (or greater). If you want to catch an error, test status code after each register() or notify() method. See Net_Growl_Response::getStatus

    Example 7: Use the Net_Growl_Response object
    <?php
    require_once 'Net/Growl.php';
    
    $notifications = array(
        'GROWL_NOTIFY_PHPERROR'
    );
    $appName  = 'PHP App Example using GNTP';
    $password = 'mamasam';
    $options  = array(
        'host'     => '192.168.1.2',
        'protocol' => 'tcp',
        'port'     => Net_Growl::GNTP_PORT,
        'debug'    => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'netgrowl.log'
    );
    
    try {
        $growl = Net_Growl::singleton($appName, $notifications, $password, $options);
        $resp  = $growl->register();
    
        if ($resp->getStatus() != 'OK') {
            die($resp);
        }
    
    } catch (Net_Growl_Exception $e) {
        echo 'Caught Growl exception: ' . $e->getMessage() . PHP_EOL;
    }
    ?>

8. Appendix A: Net_Growl API

8.1. Overview

Table 4. All classes
Name Description

Net_Growl

A PHP library that talk to Growl

Net_Growl_Application

Application object for Net_Growl

Net_Growl_Exception

Dedicated Exception for Net_Growl

Net_Growl_Udp

UDP adapter

Net_Growl_Gntp

GNTP adapter

Net_Growl_GntpMock

GNTP Mock adapter intended for test only

Net_Growl_Response

GNTP specialized response

8.2. Net_Growl Class

8.2.1. Synopsis

class Net_Growl
{
    /* constants */
    const int UDP_PORT;
    const int GNTP_PORT;
    const int PRIORITY_LOW;
    const int PRIORITY_MODERATE;
    const int PRIORITY_NORMAL;
    const int PRIORITY_HIGH;
    const int PRIORITY_EMERGENCY;

    /* properties */
    protected array $options;
    protected array $growlNotificationCallback;
    protected int $growlNotificationCount;
    protected bool $isRegistered;
    protected static object $instance;

    private object $_application;
    private int $_growlNotificationLimit;
    private resource $_fp;

    /* methods */
    public static final object singleton(mixed &$application, array $notifications [, string $password = '' [, array $options = array()]] );
    public static final void reset();
    public void __destruct();
    public void setNotificationLimit($max);
    public object getApplication();
    public bool | Net_Growl_Response register();
    public bool | Net_Growl_Response notify(string $name, string $title [, string $description = '' [, array $options = array()]] )
    public string getDefaultGrowlIcon([ bool $return = true]);
    public static void autoload($class);
    public void errorHandler(int $errno, string $errstr, string $errfile, int $errline);

    protected object __construct(mixed &$application, array $notifications [, string $password = '' [, array $options = array()]] );
    protected bool | Net_Growl_Response sendRequest(string $method, mixed $data [, bool $callback = false] );
    protected void debug(string $message [, string $priority = 'debug']);

    private string _readLine(resource $fp);
}

8.2.2. Constants

Table 5. Net_Growl Constants
Name Value Description

UDP_PORT

9887

Growl default UDP port

GNTP_PORT

23053

Growl default GNTP port

PRIORITY_LOW

-2

Growl low priority

PRIORITY_MODERATE

-1

Growl moderate priority

PRIORITY_NORMAL

0

Growl normal priority

PRIORITY_HIGH

1

Growl high priority

PRIORITY_EMERGENCY

2

Growl emergency priority

8.2.3. Methods

Table 6. Net_Growl Methods
Name Description

singleton

Makes sure there is only one Growl connection open

setNotificationLimit

Limit the number of notifications

getApplication

Returns the registered application object

register

Sends a application register to Growl

notify

Sends a notification to Growl

getDefaultGrowlIcon

Returns Growl default icon logo binary data

autoload

Autoloader for PEAR compatible classes

errorHandler

Converts standard error into exception

Net_Growl::singleton
Description

Makes sure there is only one Growl connection open.

Parameter
mixed $application

Can be either a Net_Growl_Application object or the application name string

array $notifications

List of notification types

string $password

(optional) Password for Growl

array $options

(optional) List of options :

  • host, port, protocol, timeout

    • for Growl socket server

  • passwordHashAlgorithm, encryptionAlgorithm

    • to secure communications

  • debug

    • to know what data are sent and received.

Throws
Net_Growl_Exception

if class handler does not exists

Return value

object - Net_Growl

Net_Growl::setNotificationLimit
Description

This method limits the number of notifications to be displayed on the Growl user desktop. By default, there is no limit. It is used mostly to prevent problem with notifications within loops.

Parameter
int $max

Maximum number of notifications

Throws

no exceptions thrown

Return value

void

Net_Growl::getApplication
Description

Returns the registered application object

Throws

no exceptions thrown

Return value

object - Net_Growl_Application

Net_Growl::register
Description

Sends a application register to Growl

Throws
Net_Growl_Exception

if REGISTER failed

Return value

void

Net_Growl::notify
Description

Sends a notification to Growl

Growl notifications have a name, a title, a description and a few options, depending on the kind of display plugin you use. The bubble plugin is recommended, until there is a plugin more appropriate for these kind of notifications.

The current options supported by most Growl plugins are:

 array('priority' => 0, 'sticky' => false)
  • sticky: whether the bubble stays on screen until the user clicks on it.

  • priority: a number from -2 (low) to 2 (high), default is 0 (normal).

Parameter
string $name

Notification name

string $title

Notification title

string $description

(optional) Notification description

string $options

(optional) few Notification options

Throws
Net_Growl_Exception

if NOTIFY failed

Return value

bool - true

Net_Growl::getDefaultGrowlIcon
Description

Returns Growl default icon logo binary data. Decodes data encoded with MIME base64

Parameter
bool $return

(optional) If used and set to FALSE, getDefaultGrowlIcon() will output the binary representation instead of return it

Throws

no exceptions thrown

Return value

string - icon logo binary data

Example 8: Display Growl Icon
<?php
require_once 'Net/Growl.php';

Net_Growl::getDefaultGrowlIcon(false);
?>
Net_Growl::autoload
Description

Autoloader for PEAR compatible classes

Parameter
string $class

Class name

Throws
Net_Growl_Exception

if class handler cannot be loaded

Return value

void

Net_Growl::errorhandler
Description

Throws ErrorException when a standard error occured with severity level we are asking for (uses error_reporting)

Parameter
int $errno

contains the level of the error raised

string $errstr

contains the error message

string $errfile

contains the filename that the error was raised in

string $errline

contains the line number the error was raised at

Throws
ErrorException

corresponding to standard error/warning/notice raised

Return value

void

8.3. Net_Growl_Application Class

8.3.1. Synopsis

class Net_Growl_Application
{
    /* properties */
    private string $_growlAppName;
    private string $_growlAppPassword;
    private string $_growlAppIcon;
    private array $_growlNotifications;

    /* methods */
    public object __construct(mixed $appName, array $notifications [, string $password = '' [, string $appIcon = '']] );
    public void addGrowlNotifications(array $notifications);
    public array getGrowlNotifications();
    public string getGrowlName();
    public string getGrowlPassword();
    public string getGrowlIcon();

}

8.3.2. Methods

Table 7. Net_Growl_Application Methods
Name Description

__construct

Constructs a new application to be registered by Growl

addGrowlNotifications

Adds notifications supported by this application

getGrowlNotifications

Returns the notifications accepted by Growl for this application

getGrowlName

Returns the application name for registration in Growl

getGrowlPassword

Returns the password to be used by Growl to accept notification packets

getGrowlIcon

Returns the application icon for registration in Growl

Net_Growl_Application::__construct
Description

Constructs a new application to be registered by Growl

Parameter
string $appName

Application name

array $notifications

Array of notifications

string $password

(optional) Password to be used to notify Growl

string $appIcon

(optional) Application icon

Throws

no exceptions thrown

Return value

object - Net_Growl_Application

Example 9: PEAR_Error growl handler
<?php
require_once 'Net/Growl.php';
require_once 'PEAR.php';

define('GROWL_NOTIFY_PEARERROR', 'PEAR_Error');

function growlErrors($error)
{
    static $app;

    if (!isset($app)) {
        $app = new Net_Growl_Application(
            'Net_Growl', array(GROWL_NOTIFY_PEARERROR), 'mamasam'
        );
    }

    $growl = Net_Growl::singleton(
        $app, null, null, array('host' => '192.168.1.2')
    );
    $growl->notify(GROWL_NOTIFY_PEARERROR,
        get_class($error),
        $error->message.' in '.$_SERVER['SCRIPT_NAME'],
        array('sticky' => true)
    );
}

PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'growlErrors');

PEAR::raiseError("The expected error you submitted does not exist");
?>
Net_Growl_Application::addGrowlNotifications
Description

Adds notifications supported by this application

Expected array format is:

 array('notification name' => array('option name' => 'option value'))

At the moment, only option name enabled is supported. Example:

 $notifications = array('Test Notification' => array('enabled' => true));
Parameter
array $notifications

Array of notifications to support

Throws

no exceptions thrown

Return value

void

Net_Growl_Application::getGrowlNotifications
Description

Returns the notifications accepted by Growl for this application

Expected array format is:

 array('notification name' => array('option name' => 'option value'))

At the moment, only option name enabled is supported. Example:

 $notifications = array('Test Notification' => array('enabled' => true));
 return $notifications;
Throws

no exceptions thrown

Return value

array - list of notifications type

Net_Growl_Application::getGrowlName
Description

Returns the application name for registration in Growl

Throws

no exceptions thrown

Return value

string — application name

Net_Growl_Application::getGrowlPassword
Description

Returns the password to be used by Growl to accept notification packets

Throws

no exceptions thrown

Return value

string — password

Net_Growl_Application::getGrowlIcon
Description

Returns the application icon for registration in Growl

Throws

no exceptions thrown

Return value

string — application icon (valid url) or empty if default image

8.4. Net_Growl_Exception Class

8.4.1. Synopsis

class Net_Growl_Exception extends Exception
{
}

8.4.2. Methods

Important Inherit all methods and properties from base Exception class. More details at http://www.php.net/manual/en/class.exception.php

8.5. Net_Growl_Udp Class

8.5.1. Synopsis

class Net_Growl_Udp
{
    /* methods */
    public object __construct(mixed $application [, array $notifications = array() [, string $password = '' [, array $options = array()]]] );
    public bool sendRegister();
    public bool sendNotify($name, $title, $description, $options);

}

8.5.2. Methods

Table 8. Net_Growl_Udp Methods
Name Description

__construct

Constructs a new UDP adapter

sendRegister

Sends the REGISTER message type

sendNotify

Sends the NOTIFY message type

Net_Growl_Udp::__construct
Description

Constructs a new UDP adapter

Parameter
mixed $application

Application name

array $notifications

List of notification types

string $password

(optional) Password for Growl

array $options

(optional) List of options :

  • host, port, protocol, timeout

    • for Growl socket server

  • debug

    • to know what data are sent and received.

Throws

no exceptions thrown

Return value

object - Net_Growl_Udp

Net_Growl_Udp::sendRegister
Description

Sends the REGISTER message type

Throws
Net_Growl_Exception

if remote server communication failure

Return value

true

Net_Growl_Udp::sendNotify
Description

Sends the NOTIFY message type

Throws
Net_Growl_Exception

if remote server communication failure

Return value

true

8.6. Net_Growl_Gntp Class

8.6.1. Synopsis

class Net_Growl_Gntp
{
    /* properties */
    private array $_passwordHashAlgorithm;

    /* methods */
    public object __construct(mixed $application [, array $notifications = array() [, string $password = '' [, array $options = array()]]] );
    public Net_Growl_Response sendRegister();
    public Net_Growl_Response sendNotify($name, $title, $description, $options);

    protected string genMessageStructure($method, $data [, $binaries = false]);

    private array _genKey($password);
    private array _genEncryption($key, $plainText);
    private string _toBool($value);
}

8.6.2. Methods

Table 9. Net_Growl_Gntp Methods
Name Description

__construct

Constructs a new GNTP adapter

sendRegister

Sends the REGISTER message type

sendNotify

Sends the NOTIFY message type

Net_Growl_Gntp::__construct
Description

Constructs a new GNTP adapter

Parameter
mixed $application

Application name

array $notifications

List of notification types

string $password

(optional) Password for Growl

array $options

(optional) List of options :

  • host, port, protocol, timeout

    • for Growl socket server

  • passwordHashAlgorithm, encryptionAlgorithm

    • to secure communications

  • debug

    • to know what data are sent and received.

Throws

no exceptions thrown

Return value

object - Net_Growl_Gntp

Net_Growl_Gntp::sendRegister
Description

Sends the REGISTER message type

Throws
Net_Growl_Exception

if remote server communication failure

Return value

Net_Growl_Response object

Net_Growl_Gntp::sendNotify
Description

Sends the NOTIFY message type

Throws
Net_Growl_Exception

if remote server communication failure

Return value

Net_Growl_Response object

8.7. Net_Growl_GntpMock Class

8.7.1. Synopsis

class Net_Growl_GntpMock
{
    /* properties */
    protected $responses = array();

    /* methods */
    public object __construct(mixed $application [, array $notifications = array() [, string $password = '' [, array $options = array()]]] );
    public Net_Growl_Response sendRegister();
    public Net_Growl_Response sendNotify($name, $title, $description, $options);
    public void addResponse($response)

    protected Net_Growl_Response sendRequest()
    protected Net_Growl_Response createResponseFromString($str)
    protected Net_Growl_Response createResponseFromFile($fp)
}

8.7.2. Methods

Table 10. Net_Growl_GntpMock Methods
Name Description

__construct

Constructs a new GNTP Mock adapter

sendRegister

Mock sending the REGISTER message type

sendNotify

Mock sending the NOTIFY message type

addResponse

Adds response to the queue

Net_Growl_Gntp::__construct
Description

Constructs a new GNTP adapter

Parameter
mixed $application

Application name

array $notifications

List of notification types

string $password

(optional) Password for Growl

array $options

(optional) List of options :

  • host, port, protocol, timeout

    • for Growl socket server

  • passwordHashAlgorithm, encryptionAlgorithm

    • to secure communications

  • debug

    • to know what data are sent and received.

Throws

no exceptions thrown

Return value

object - Net_Growl_GntpMock

Net_Growl_GntpMock::sendRegister
Description

Mock sending the REGISTER message type

Throws
Net_Growl_Exception

if Net_Growl_Response not received

Return value

Net_Growl_Response object

Net_Growl_GntpMock::sendNotify
Description

Mock sending the NOTIFY message type

Throws
Net_Growl_Exception

if Net_Growl_Response not received

Return value

Net_Growl_Response object

Net_Growl_GntpMock::addResponse
Description

Adds response expected to the queue

Throws
Net_Growl_Exception

if $response is different to file pointer, string or Net_Growl_Exception

Return value

void

8.8. Net_Growl_Response Class

8.8.1. Synopsis

class Net_Growl_Response
{
    /* properties */
    protected string $version;
    protected string $code;
    protected string $action;
    protected integer $errorCode;
    protected string $errorDescription;
    protected string $machineName;
    protected string $softwareName;
    protected string $softwareVersion;
    protected string $platformName;
    protected string $platformVersion;
    protected string $body;

    /* methods */
    public object __construct(string $statusLine );
    public void appendBody(string $bodyChunk );
    public string getVersion();
    public string getStatus();
    public string getResponseAction();
    public integer getErrorCode();
    public string getErrorDescription();
    public string getOriginMachineName();
    public string getOriginSoftwareName();
    public string getOriginSoftwareVersion();
    public string getOriginPlatformName();
    public string getOriginPlatformVersion();
    public string __toString();

}

8.8.2. Methods

Table 11. Net_Growl_Response Methods
Name Description

__construct

Constructs a new GNTP specialized response

appendBody

Append a string to the response body

getVersion

Returns GNTP protocol version

getStatus

Returns the status code

getResponseAction

Returns the request action

getErrorCode

Returns the error code

getErrorDescription

Returns the error description

getOriginMachineName

Returns the machine name/host name of the sending computer

getOriginSoftwareName

Returns the identity of the sending framework

getOriginSoftwareVersion

Returns the version of the sending framework

getOriginPlatformName

Returns the identify of the sending computer OS/platform

getOriginPlatformVersion

Returns the version of the sending computer OS/platform

__toString

Returns the String representation of the Growl response

Net_Growl_Response::__construct
Description

Constructs a specialized response to a GNTP request

Parameter
mixed $statusLine

Response status line (e.g. "GNTP/1.0 -OK NONE")

Throws

no exceptions thrown

Return value

object - Net_Growl_Response

Net_Growl_Response::appendBody
Description

Append a string to the response body excluding the protocol identifier, version, message type, and encryption algorithm id

Throws

no exceptions thrown

Return value

void

Net_Growl_Response::getVersion
Description

Returns GNTP protocol version (e.g. 1.0, 1.1)

Throws

no exceptions thrown

Return value

string

Net_Growl_Response::getStatus
Description

Returns the status code (OK | ERROR)

Throws

no exceptions thrown

Return value

string

Net_Growl_Response::getResponseAction
Description

Returns the request action (REGITER | NOTIFY)

Throws

no exceptions thrown

Return value

string

Net_Growl_Response::getErrorCode
Description

Returns the error code

Throws

no exceptions thrown

Return value

integer

Net_Growl_Response::getErrorDescription
Description

Returns the error description

Throws

no exceptions thrown

Return value

string

Net_Growl_Response::getOriginMachineName
Description

Returns the machine name/host name of the sending computer

Throws

no exceptions thrown

Return value

string

Net_Growl_Response::getOriginSoftwareName
Description

Returns the identity of the sending framework * Example1: Growl/Win * Example2: GrowlAIRConnector

Throws

no exceptions thrown

Return value

string

Net_Growl_Response::getOriginSoftwareVersion
Description

Returns the version of the sending framework * Example1: 2.0.0.28 * Example2: 1.2

Throws

no exceptions thrown

Return value

string

Net_Growl_Response::getOriginPlatformName
Description

Returns the identify of the sending computer OS/platform * Example1: Microsoft Windows NT 5.1.2600 Service Pack 3 * Example2: Mac OS X

Throws

no exceptions thrown

Return value

string

Net_Growl_Response::getOriginPlatformVersion
Description

Returns the version of the sending computer OS/platform * Example1: 5.1.2600.196608 * Example2: 10.6

Throws

no exceptions thrown

Return value

string

Net_Growl_Response::__toString
Description

Returns the String representation of the Growl response * Example1: Response REGISTER OK (Growl/Win 2.0.0.28) * Example2: Response ERROR 300 No notifications registered (Growl/Win 2.0.0.28)

Throws

no exceptions thrown

Return value

string

This work is licensed under the BSD License.

The full legal text of the license is given below.

 Copyright (c) 2009-2010, Laurent Laville <pear@laurent-laville.org>
                          Bertrand Mansion <bmansion@mamasam.com>

 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

     * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
     * Neither the name of the authors nor the names of its contributors
       may be used to endorse or promote products derived from this software
       without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.

10. Appendix C: Glossary

GNTP

Growl uses GNTP (Growl Notification Transport Protocol) to send notifications. GNTP is a MIME-like format.

Growl

Growl is a global notification system for Mac OS X. Any application can send a notification to Growl, which will display an attractive message on your screen. Growl currently works with a growing number of applications.

Notification

Notifications are a way for your applications to provide you with new information, without you having to switch from the application you’re already in.

UDP

Growl uses on all platforms the basic UDP (User Datagram Protocol) to send notifications. UDP is a binary format.