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

Source for file Application.php

Documentation is available at Application.php

  1. <?php
  2. // +-----------------------------------------------------------------------+
  3. // | Copyright (c) 2006, Bertrand Mansion                                  |
  4. // | All rights reserved.                                                  |
  5. // |                                                                       |
  6. // | Redistribution and use in source and binary forms, with or without    |
  7. // | modification, are permitted provided that the following conditions    |
  8. // | are met:                                                              |
  9. // |                                                                       |
  10. // | o Redistributions of source code must retain the above copyright      |
  11. // |   notice, this list of conditions and the following disclaimer.       |
  12. // | o Redistributions in binary form must reproduce the above copyright   |
  13. // |   notice, this list of conditions and the following disclaimer in the |
  14. // |   documentation and/or other materials provided with the distribution.|
  15. // | o The names of the authors may not be used to endorse or promote      |
  16. // |   products derived from this software without specific prior written  |
  17. // |   permission.                                                         |
  18. // |                                                                       |
  19. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
  20. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
  21. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
  22. // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
  23. // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
  24. // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
  25. // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
  26. // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
  27. // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |
  28. // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
  29. // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |
  30. // |                                                                       |
  31. // +-----------------------------------------------------------------------+
  32. // | Author: Bertrand Mansion <golgote@mamasam.com>                        |
  33. // +-----------------------------------------------------------------------+
  34. //
  35. // $Id $
  36.  
  37. /**
  38.  * Application object for {@link Net_Growl}
  39.  * 
  40.  * This object represents an application containing the notifications
  41.  * to be registered by {@link http://growl.info Growl}. Feel free to use
  42.  * your own application object as long as it implements the few public
  43.  * getter methods:
  44.  * - {@link Net_Growl_Application::getGrowlNotifications()}
  45.  * - {@link Net_Growl_Application::getGrowlName()}
  46.  * - {@link Net_Growl_Application::getGrowlPassword()}
  47.  *
  48.  * @author    Bertrand Mansion <golgote@mamasam.com>
  49.  * @copyright 2006
  50.  * @license   http://www.opensource.org/licenses/bsd-license.php BSD License
  51.  * @package   Net_Growl
  52.  * @link      http://growl.info Growl Homepage
  53.  */
  54. {
  55.     /**
  56.      * Name of application to be registered by Growl
  57.      * @var string 
  58.      * @access private
  59.      */
  60.     var $_growlAppName;
  61.  
  62.     /**
  63.      * Password for notifications
  64.      * @var string 
  65.      * @access private
  66.      */
  67.     var $_growlAppPassword '';
  68.  
  69.     /**
  70.      * Array of notifications
  71.      * @var array 
  72.      * @access private
  73.      */
  74.     var $_growlNotifications = array();
  75.  
  76.     /**
  77.      * Constructor
  78.      * Constructs a new application to be registered by Growl
  79.      *
  80.      * @param   string      Application name
  81.      * @param   array       Array of notifications
  82.      * @param   string      Password to be used to notify Growl
  83.      * @access  public
  84.      * @see     Net_Growl_Application::addGrowlNotifications()
  85.      */
  86.     function Net_Growl_Application($appName$notifications$password '')
  87.     {
  88.         $this->_growlAppName $appName;
  89.         $this->_growlAppPassword (empty($password)) '' $password;
  90.         if (!empty($notifications&& is_array($notifications)) {
  91.             $this->addGrowlNotifications($notifications);
  92.         }
  93.     }
  94.  
  95.     /**
  96.      * Adds notifications supported by this application
  97.      *
  98.      * Expected array format is:
  99.      * <pre>
  100.      * array('notification name' => array('option name' => 'option value'))
  101.      * </pre>
  102.      * At the moment, only option name 'enabled' is supported. Example:
  103.      * <code>
  104.      * $notifications = array('Test Notification' => array('enabled' => true));
  105.      * </code>
  106.      *
  107.      * @access  public
  108.      * @param array     Array of notifications to support
  109.      */
  110.     function addGrowlNotifications($notifications)
  111.     {
  112.         $default $this->_getGrowlNotificationDefaultOptions();
  113.         foreach ($notifications as $name => $options{
  114.             if (is_int($name)) {
  115.                 $name $options;
  116.                 $options $default;
  117.             elseif (!empty($options&& is_array($options)) {
  118.                 $options array_merge($default$options);
  119.             }
  120.             $this->_growlNotifications[$name$options;
  121.         }
  122.     }
  123.  
  124.     function _getGrowlNotificationDefaultOptions()
  125.     {
  126.         return array('enabled' => true);
  127.     }
  128.  
  129.     /**
  130.      * Returns the notifications accepted by Growl for this application
  131.      *
  132.      * Expected array format is:
  133.      * <pre>
  134.      * array('notification name' => array('option name' => 'option value'))
  135.      * </pre>
  136.      * At the moment, only option name 'enabled' is supported. Example:
  137.      * <code>
  138.      * $notifications = array('Test Notification' => array('enabled' => true));
  139.      * return $notifications;
  140.      * </code>
  141.      *
  142.      * @access  public
  143.      * @return array notifications
  144.      */
  145.     function &getGrowlNotifications()
  146.     {
  147.         return $this->_growlNotifications;
  148.     }
  149.  
  150.     /**
  151.      * Returns the application name for registration in Growl
  152.      *
  153.      * @access  public
  154.      * @return string application name
  155.      */
  156.     function getGrowlName()
  157.     {
  158.         return $this->_growlAppName;
  159.     }
  160.  
  161.     /**
  162.      * Returns the password to be used by Growl to accept notification packets
  163.      *
  164.      * @access  public
  165.      * @return string password
  166.      */
  167.     function getGrowlPassword()
  168.     {
  169.         return $this->_growlAppPassword;
  170.     }
  171. }
  172. ?>

Documentation generated on Mon, 11 Mar 2019 14:38:44 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.