00001: <?php
00002: /**
00003: * Copyright (c) 2009-2010, Laurent Laville <pear@laurent-laville.org>
00004: * Bertrand Mansion <bmansion@mamasam.com>
00005: *
00006: * All rights reserved.
00007: *
00008: * Redistribution and use in source and binary forms, with or without
00009: * modification, are permitted provided that the following conditions
00010: * are met:
00011: *
00012: * * Redistributions of source code must retain the above copyright
00013: * notice, this list of conditions and the following disclaimer.
00014: * * Redistributions in binary form must reproduce the above copyright
00015: * notice, this list of conditions and the following disclaimer in the
00016: * documentation and/or other materials provided with the distribution.
00017: * * Neither the name of the authors nor the names of its contributors
00018: * may be used to endorse or promote products derived from this software
00019: * without specific prior written permission.
00020: *
00021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00022: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
00025: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00026: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00027: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00029: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00030: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031: * POSSIBILITY OF SUCH DAMAGE.
00032: *
00033: * PHP version 5
00034: *
00035: * @category Networking
00036: * @package Net_Growl
00037: * @author Laurent Laville <pear@laurent-laville.org>
00038: * @author Bertrand Mansion <bmansion@mamasam.com>
00039: * @license http://www.opensource.org/licenses/bsd-license.php BSD
00040: * @version CVS: $Id:$
00041: * @link http://growl.laurent-laville.org/
00042: * @since File available since Release 0.9.0
00043: */
00044:
00045: /**
00046: * Application object for {@link Net_Growl}
00047: *
00048: * This object represents an application containing the notifications
00049: * to be registered by {@link http://growl.info Growl}. Feel free to use
00050: * your own application object as long as it implements the few public
00051: * getter methods:
00052: * - {@link Net_Growl_Application::getGrowlNotifications()}
00053: * - {@link Net_Growl_Application::getGrowlName()}
00054: * - {@link Net_Growl_Application::getGrowlPassword()}
00055: *
00056: * @category Networking
00057: * @package Net_Growl
00058: * @author Laurent Laville <pear@laurent-laville.org>
00059: * @author Bertrand Mansion <bmansion@mamasam.com>
00060: * @license http://www.opensource.org/licenses/bsd-license.php BSD
00061: * @version Release: @package_version@
00062: * @link http://growl.laurent-laville.org/
00063: * @since Class available since Release 0.9.0
00064: */
00065: class Net_Growl_Application
00066: {
00067: /**
00068: * Name of application to be registered by Growl
00069: * @var string
00070: */
00071: private $_growlAppName;
00072:
00073: /**
00074: * Password for notifications
00075: * @var string
00076: */
00077: private $_growlAppPassword = '';
00078:
00079: /**
00080: * Name of application to be registered by Growl
00081: * @var string
00082: */
00083: private $_growlAppIcon = '';
00084:
00085: /**
00086: * Array of notifications
00087: * @var array
00088: */
00089: private $_growlNotifications = array();
00090:
00091: /**
00092: * Constructor
00093: * Constructs a new application to be registered by Growl
00094: *
00095: * @param string $appName Application name
00096: * @param array $notifications Array of notifications
00097: * @param string $password (optional) Password to be used to notify Growl
00098: * @param string $appIcon (optional) Application icon
00099: *
00100: * @return void
00101: * @see addGrowlNotifications()
00102: */
00103: public function __construct($appName, $notifications, $password = '',
00104: $appIcon = ''
00105: ) {
00106: $this->_growlAppName = $appName;
00107: $this->_growlAppPassword = (empty($password)) ? '' : $password;
00108: $this->_growlAppIcon = $appIcon;
00109: if (!empty($notifications) && is_array($notifications)) {
00110: $this->addGrowlNotifications($notifications);
00111: }
00112: }
00113:
00114: /**
00115: * Adds notifications supported by this application
00116: *
00117: * Expected array format is:
00118: * <pre>
00119: * array('notification name' => array('option name' => 'option value'))
00120: * </pre>
00121: * At the moment, only option name 'enabled' is supported. Example:
00122: * <code>
00123: * $notifications = array('Test Notification' => array('enabled' => true));
00124: * </code>
00125: *
00126: * @param array $notifications Array of notifications to support
00127: *
00128: * @return void
00129: */
00130: public function addGrowlNotifications($notifications)
00131: {
00132: if (!is_array($notifications)) {
00133: // wrong parameter
00134: return;
00135: }
00136:
00137: $default = array('enabled' => true);
00138: foreach ($notifications as $name => $options) {
00139: if (is_int($name)) {
00140: $name = $options;
00141: $options = $default;
00142: } elseif (is_array($options)) {
00143: $options = array_merge($default, $options);
00144: }
00145: $this->_growlNotifications[$name] = $options;
00146: }
00147: }
00148:
00149: /**
00150: * Returns the notifications accepted by Growl for this application
00151: *
00152: * Expected array format is:
00153: * <pre>
00154: * array('notification name' => array('option name' => 'option value'))
00155: * </pre>
00156: * At the moment, only option name 'enabled' is supported. Example:
00157: * <code>
00158: * $notifications = array('Test Notification' => array('enabled' => true));
00159: * return $notifications;
00160: * </code>
00161: *
00162: * @return array notifications
00163: */
00164: public function getGrowlNotifications()
00165: {
00166: return $this->_growlNotifications;
00167: }
00168:
00169: /**
00170: * Returns the application name for registration in Growl
00171: *
00172: * @return string application name
00173: */
00174: public function getGrowlName()
00175: {
00176: return $this->_growlAppName;
00177: }
00178:
00179: /**
00180: * Returns the password to be used by Growl to accept notification packets
00181: *
00182: * @return string password
00183: */
00184: public function getGrowlPassword()
00185: {
00186: return $this->_growlAppPassword;
00187: }
00188:
00189: /**
00190: * Returns the application icon for registration in Growl
00191: *
00192: * @return string application icon (valid url) or empty if default image
00193: */
00194: public function getGrowlIcon()
00195: {
00196: return $this->_growlAppIcon;
00197: }
00198: }
00199: ?>