Net_Growl
[ class tree: Net_Growl ] [ index: Net_Growl ] [ all elements ]

Source for file gntpAdapterSocketCallbacks.php

Documentation is available at gntpAdapterSocketCallbacks.php

  1. <?php
  2. /**
  3.  * Socket callbacks example
  4.  * that send notifications to Growl using the new GNTP/1.0 protocol
  5.  *
  6.  * Callbacks are sent back to the sending application
  7.  * when an action is taken in response to a notification.
  8.  *
  9.  * PHP version 5
  10.  *
  11.  * @category Networking
  12.  * @package  Net_Growl
  13.  * @author   Laurent Laville <pear@laurent-laville.org>
  14.  * @author   Bertrand Mansion <bmansion@mamasam.com>
  15.  * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
  16.  * @version  SVN: Release: 2.7.0
  17.  * @link     http://growl.laurent-laville.org/
  18.  * @since    File available since Release 2.0.0b2
  19.  */
  20.  
  21. require_once 'Net/Growl/Autoload.php';
  22.  
  23. /**
  24.  * Callback function when notification response is returned
  25.  *
  26.  * @param string $result    Notification-Callback-Result: header, result
  27.  *                           [CLICKED|CLOSED|TIMEDOUT] | [CLICK|CLOSE|TIMEOUT]
  28.  * @param string $context   Notification-Callback-Context: header, result
  29.  *                           from the original request
  30.  * @param string $type      Notification-Callback-Context-Type: header, result
  31.  *                           from the original request
  32.  * @param string $timestamp Notification-Callback-Timestamp: header, result
  33.  *                           The date and time the callback occurred
  34.  *
  35.  * @return void 
  36.  */
  37. function cbNotify($result$context$type$timestamp)
  38. {
  39.     printf(
  40.         "Notification Callback Result => %s: %s (%s) at %s \n\n",
  41.         $result$context$type$timestamp
  42.     );
  43. }
  44.  
  45. // Notification Type definitions
  46. define('GROWL_NOTIFY_STATUS',   'STATUS');
  47. define('GROWL_NOTIFY_PHPERROR''PHPERROR');
  48.  
  49. // define a PHP application that sends notifications to Growl
  50. $appName 'PEAR/Net_Growl ' basename(__FILE__'.php');
  51.  
  52. $notifications = array(
  53.     GROWL_NOTIFY_STATUS => array(
  54.         'display' => 'Status',
  55.     ),
  56.  
  57.     GROWL_NOTIFY_PHPERROR => array(
  58.         'icon'    => 'http://www.laurent-laville.org/growl/images/firephp.png',
  59.         'display' => 'Error-Log'
  60.     )
  61. );
  62.  
  63. $password '';
  64. $options  = array(
  65.     'protocol' => 'gntp',
  66.     'AppIcon'  => 'http://www.laurent-laville.org/growl/images/Help.png',
  67.     'debug'    => dirname(__FILE__. DIRECTORY_SEPARATOR .
  68.         basename(__FILE__'.php''.log'
  69. );
  70.  
  71. try {
  72.     $growl Net_Growl::singleton($appName$notifications$password$options);
  73.     $growl->register();
  74.  
  75.     $name        GROWL_NOTIFY_STATUS;
  76.     $title       'Congratulation';
  77.     $description 'You have successfully installed PEAR/Net_Growl.';
  78.     $options     = array(
  79.         'ID'                  => 123456,
  80.         'CallbackContext'     => 'this is my context',
  81.         'CallbackContextType' => 'STRING',
  82.         'CallbackFunction'    => 'cbNotify'
  83.     );
  84.     $growl->publish($name$title$description$options);
  85.  
  86.     $name        GROWL_NOTIFY_PHPERROR;
  87.     $title       'New Error';
  88.     $description 'You have a new PHP error in your script.';
  89.     $options     = array(
  90.         'priority' => Net_Growl::PRIORITY_HIGH,
  91.     );
  92.     $growl->publish($name$title$description$options);
  93.  
  94.     $name        GROWL_NOTIFY_STATUS;
  95.     $title       'Welcome';
  96.     $description "Welcome in PHP/GNTP world ! \n"
  97.                  . "New GNTP protocol add icon support.";
  98.     $options     = array(
  99.         'icon'   => 'http://www.laurent-laville.org/growl/images/unknown.png',
  100.         'sticky' => false,
  101.     );
  102.     $growl->publish($name$title$description$options);
  103.  
  104. catch (Net_Growl_Exception $e{
  105.     echo 'Caught Growl exception: ' $e->getMessage(. PHP_EOL;
  106. }

Documentation generated on Tue, 29 Jan 2013 18:30:05 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.