1. Introduction
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 :
-
PEAR::Net_Growl 0.7.0 - UDP only
-
http://growl.laurent-laville.org/bin/Net_Growl-0.9.0b2.tgz 0.9.0 beta2 - UDP (full) + GNTP (partially)
|
|
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
-
Growl requires Mac OS X 10.5 or higher.
-
Growl for Windows is a Windows-compatible version of Growl, a notification system for Mac OS X.
-
mcrypt extension when using GNTP adapter and encryt feature
4. Installing Net_Growl
|
|
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:
-
Download a release archive from http://growl.laurent-laville.org/bin/
-
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)
|
|
Do not register each time you send a new notification. It’s unnecessary. |
|
|
Net_Growl will register your application at first notification send, if it was not implicitly called before with Net_Growl::register(). |
<?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.
<?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
|
|
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)
Followed by
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
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
6. Secure your communication
|
|
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.
|
|
By default, authorization is not required for requests orginating on the local machine. |
| 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 |
| 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) |
|
|
All encryption algorithms should use a block mode of CBC (Cipher Block Chaining) and PKCS5 (PKCS7) padding. |
|
|
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). |
| 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 :
-
password hash algorithm, see the supported hashing algorithms.
-
encryption algorithm, see the supported encryption algorithms.
<?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
-
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(); ?>
You can also suppress timeout by setting value to zero. -
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; } ?>
All errors produced by Net_Growl raise a Net_Growl_Exception
-
-
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; } ?>
-
My favorite application icons are not shown
-
URL given are not valid or not reachable
-
URL are good but resources are invalid images
If you give URL/resource that are not valid, Net_Growl will use default icon returns by Net_Growl::getDefaultGrowlIcon method.
-
-
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
| Name | Description |
|---|---|
A PHP library that talk to Growl |
|
Application object for Net_Growl |
|
Dedicated Exception for Net_Growl |
|
UDP adapter |
|
GNTP adapter |
|
GNTP Mock adapter intended for test only |
|
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
| 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
| Name | Description |
|---|---|
Makes sure there is only one Growl connection open |
|
Limit the number of notifications |
|
Returns the registered application object |
|
Sends a application register to Growl |
|
Sends a notification to Growl |
|
Returns Growl default icon logo binary data |
|
Autoloader for PEAR compatible classes |
|
Converts standard error into exception |
Net_Growl::singleton
Makes sure there is only one Growl connection open.
- 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.
-
-
- Net_Growl_Exception
-
if class handler does not exists
object - Net_Growl
Net_Growl::setNotificationLimit
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.
- int $max
-
Maximum number of notifications
no exceptions thrown
void
Net_Growl::getApplication
Returns the registered application object
no exceptions thrown
object - Net_Growl_Application
Net_Growl::register
Sends a application register to Growl
- Net_Growl_Exception
-
if REGISTER failed
void
Net_Growl::notify
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).
- string $name
-
Notification name
- string $title
-
Notification title
- string $description
-
(optional) Notification description
- string $options
-
(optional) few Notification options
- Net_Growl_Exception
-
if NOTIFY failed
bool - true
Net_Growl::getDefaultGrowlIcon
Returns Growl default icon logo binary data. Decodes data encoded with MIME base64
- bool $return
-
(optional) If used and set to FALSE, getDefaultGrowlIcon() will output the binary representation instead of return it
no exceptions thrown
string - icon logo binary data
<?php require_once 'Net/Growl.php'; Net_Growl::getDefaultGrowlIcon(false); ?>
Net_Growl::autoload
Autoloader for PEAR compatible classes
- string $class
-
Class name
- Net_Growl_Exception
-
if class handler cannot be loaded
void
Net_Growl::errorhandler
Throws ErrorException when a standard error occured with severity level we are asking for (uses error_reporting)
- 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
- ErrorException
-
corresponding to standard error/warning/notice raised
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
| Name | Description |
|---|---|
Constructs a new application to be registered by Growl |
|
Adds notifications supported by this application |
|
Returns the notifications accepted by Growl for this application |
|
Returns the application name for registration in Growl |
|
Returns the password to be used by Growl to accept notification packets |
|
Returns the application icon for registration in Growl |
Net_Growl_Application::__construct
Constructs a new application to be registered by Growl
- string $appName
-
Application name
- array $notifications
-
Array of notifications
- string $password
-
(optional) Password to be used to notify Growl
- string $appIcon
-
(optional) Application icon
no exceptions thrown
object - Net_Growl_Application
<?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
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));
- array $notifications
-
Array of notifications to support
no exceptions thrown
void
Net_Growl_Application::getGrowlNotifications
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;
no exceptions thrown
array - list of notifications type
Net_Growl_Application::getGrowlName
Returns the application name for registration in Growl
no exceptions thrown
string — application name
Net_Growl_Application::getGrowlPassword
Returns the password to be used by Growl to accept notification packets
no exceptions thrown
string — password
Net_Growl_Application::getGrowlIcon
Returns the application icon for registration in Growl
no exceptions thrown
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
|
|
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
| Name | Description |
|---|---|
Constructs a new UDP adapter |
|
Sends the REGISTER message type |
|
Sends the NOTIFY message type |
Net_Growl_Udp::__construct
Constructs a new UDP adapter
- 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.
-
-
no exceptions thrown
object - Net_Growl_Udp
Net_Growl_Udp::sendRegister
Sends the REGISTER message type
- Net_Growl_Exception
-
if remote server communication failure
true
Net_Growl_Udp::sendNotify
Sends the NOTIFY message type
- Net_Growl_Exception
-
if remote server communication failure
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
| Name | Description |
|---|---|
Constructs a new GNTP adapter |
|
Sends the REGISTER message type |
|
Sends the NOTIFY message type |
Net_Growl_Gntp::__construct
Constructs a new GNTP adapter
- 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.
-
-
no exceptions thrown
object - Net_Growl_Gntp
Net_Growl_Gntp::sendRegister
Sends the REGISTER message type
- Net_Growl_Exception
-
if remote server communication failure
Net_Growl_Response object
Net_Growl_Gntp::sendNotify
Sends the NOTIFY message type
- Net_Growl_Exception
-
if remote server communication failure
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
| Name | Description |
|---|---|
Constructs a new GNTP Mock adapter |
|
Mock sending the REGISTER message type |
|
Mock sending the NOTIFY message type |
|
Adds response to the queue |
Net_Growl_Gntp::__construct
Constructs a new GNTP adapter
- 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.
-
-
no exceptions thrown
object - Net_Growl_GntpMock
Net_Growl_GntpMock::sendRegister
Mock sending the REGISTER message type
- Net_Growl_Exception
-
if Net_Growl_Response not received
Net_Growl_Response object
Net_Growl_GntpMock::sendNotify
Mock sending the NOTIFY message type
- Net_Growl_Exception
-
if Net_Growl_Response not received
Net_Growl_Response object
Net_Growl_GntpMock::addResponse
Adds response expected to the queue
- Net_Growl_Exception
-
if $response is different to file pointer, string or Net_Growl_Exception
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
| Name | Description |
|---|---|
Constructs a new GNTP specialized response |
|
Append a string to the response body |
|
Returns GNTP protocol version |
|
Returns the status code |
|
Returns the request action |
|
Returns the error code |
|
Returns the error description |
|
Returns the machine name/host name of the sending computer |
|
Returns the identity of the sending framework |
|
Returns the version of the sending framework |
|
Returns the identify of the sending computer OS/platform |
|
Returns the version of the sending computer OS/platform |
|
Returns the String representation of the Growl response |
Net_Growl_Response::__construct
Constructs a specialized response to a GNTP request
- mixed $statusLine
-
Response status line (e.g. "GNTP/1.0 -OK NONE")
no exceptions thrown
object - Net_Growl_Response
Net_Growl_Response::appendBody
Append a string to the response body excluding the protocol identifier, version, message type, and encryption algorithm id
no exceptions thrown
void
Net_Growl_Response::getVersion
Returns GNTP protocol version (e.g. 1.0, 1.1)
no exceptions thrown
string
Net_Growl_Response::getStatus
Returns the status code (OK | ERROR)
no exceptions thrown
string
Net_Growl_Response::getResponseAction
Returns the request action (REGITER | NOTIFY)
no exceptions thrown
string
Net_Growl_Response::getErrorCode
Returns the error code
no exceptions thrown
integer
Net_Growl_Response::getErrorDescription
Returns the error description
no exceptions thrown
string
Net_Growl_Response::getOriginMachineName
Returns the machine name/host name of the sending computer
no exceptions thrown
string
Net_Growl_Response::getOriginSoftwareName
Returns the identity of the sending framework * Example1: Growl/Win * Example2: GrowlAIRConnector
no exceptions thrown
string
Net_Growl_Response::getOriginSoftwareVersion
Returns the version of the sending framework * Example1: 2.0.0.28 * Example2: 1.2
no exceptions thrown
string
Net_Growl_Response::getOriginPlatformName
Returns the identify of the sending computer OS/platform * Example1: Microsoft Windows NT 5.1.2600 Service Pack 3 * Example2: Mac OS X
no exceptions thrown
string
Net_Growl_Response::getOriginPlatformVersion
Returns the version of the sending computer OS/platform * Example1: 5.1.2600.196608 * Example2: 10.6
no exceptions thrown
string
Net_Growl_Response::__toString
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)
no exceptions thrown
string
9. Appendix B: Copyright
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.