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

Source for file Notification.php

Documentation is available at Notification.php

  1. <?php
  2. // +-----------------------------------------------------------------------+
  3. // | Copyright (c) 2005, 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 <bmansion@mamasam.com>                       |
  33. // |         Stephan Schmidt <schst@php.net>                               |
  34. // +-----------------------------------------------------------------------+
  35. //
  36. // $Id: Notification.php 284686 2009-07-24 05:22:17Z clockwerx $
  37.  
  38. /**
  39.  * Default state of the notification
  40.  */
  41. define('EVENT_NOTIFICATION_STATE_DEFAULT'0);
  42.  
  43. /**
  44.  * Notification has been cancelled
  45.  */
  46. define('EVENT_NOTIFICATION_STATE_CANCELLED'1);
  47.  
  48. /**
  49.  * A Notification object
  50.  *
  51.  * The Notification object can be easily subclassed and serves as a container
  52.  * for the information about the notification. It holds an object which is
  53.  * usually a reference to the object that posted the notification,
  54.  * a notification name used to identify the notification and some user
  55.  * information which can be anything you need.
  56.  * 
  57.  * @category   Event
  58.  * @package    Event_Dispatcher
  59.  * @author     Bertrand Mansion <bmansion@mamasam.com>
  60.  * @author     Stephan Schmidt <schst@php.net>
  61.  * @copyright  1997-2005 The PHP Group
  62.  * @license    http://www.opensource.org/licenses/bsd-license.php BSD License
  63.  * @version    Release: @package_version@
  64.  * @link       http://pear.php.net/package/Event_Dispatcher
  65.  */
  66. {
  67.     /**
  68.      * name of the notofication
  69.      * @var string 
  70.      * @access private
  71.      */
  72.     var $_notificationName;
  73.     
  74.     /**
  75.      * object of interesed (the sender of the notification, in most cases)
  76.      * @var object 
  77.      * @access private
  78.      */
  79.     var $_notificationObject;
  80.     
  81.     /**
  82.      * additional information about the notification
  83.      * @var mixed 
  84.      * @access private
  85.      */
  86.     var $_notificationInfo = array();
  87.  
  88.     /**
  89.      * state of the notification
  90.      *
  91.      * This may be:
  92.      * - EVENT_NOTIFICATION_STATE_DEFAULT
  93.      * - EVENT_NOTIFICATION_STATE_CANCELLED
  94.      *
  95.      * @var integer 
  96.      * @access private
  97.      */
  98.     var $_notificationState = EVENT_NOTIFICATION_STATE_DEFAULT;
  99.     
  100.     /**
  101.      * amount of observers that received this notification
  102.      * @var mixed 
  103.      * @access private
  104.      */
  105.     var $_notificationCount = 0;
  106.  
  107.     /**
  108.      * Constructor
  109.      *
  110.      * @access  public
  111.      * @param   object      The object of interest for the notification,
  112.      *                       usually is the posting object
  113.      * @param   string      Notification name
  114.      * @param   array       Free information array
  115.      */
  116.     function Event_Notification(&$object$name$info = array())
  117.     {
  118.         $this->_notificationObject =$object;
  119.         $this->_notificationName   $name;
  120.         $this->_notificationInfo   $info;
  121.     }
  122.  
  123.     /**
  124.      * Returns the notification name
  125.      * @return  string Notification name
  126.      */
  127.     function getNotificationName()
  128.     {
  129.         return $this->_notificationName;
  130.     }
  131.  
  132.     /**
  133.      * Returns the contained object
  134.      * @return  object Contained object
  135.      */
  136.     function &getNotificationObject()
  137.     {
  138.         return $this->_notificationObject;
  139.     }
  140.  
  141.     /**
  142.      * Returns the user info array
  143.      * @return  array user info
  144.      */
  145.     function getNotificationInfo()
  146.     {
  147.         return $this->_notificationInfo;    
  148.     }
  149.  
  150.    /**
  151.     * Increase the internal count
  152.     *
  153.     * @access   public
  154.     */
  155.     function increaseNotificationCount()
  156.     {
  157.         ++$this->_notificationCount;
  158.     }
  159.     
  160.    /**
  161.     * Get the number of posted notifications
  162.     *
  163.     * @access   public
  164.     * @return   int 
  165.     */
  166.     function getNotificationCount()
  167.     {
  168.         return $this->_notificationCount;
  169.     }
  170.     
  171.    /**
  172.     * Cancel the notification
  173.     *
  174.     * @access   public
  175.     * @return   void 
  176.     */
  177.     function cancelNotification()
  178.     {
  179.         $this->_notificationState EVENT_NOTIFICATION_STATE_CANCELLED;
  180.     }
  181.  
  182.    /**
  183.     * Checks whether the notification has been cancelled
  184.     *
  185.     * @access   public
  186.     * @return   boolean 
  187.     */
  188.     function isNotificationCancelled()
  189.     {
  190.         return ($this->_notificationState === EVENT_NOTIFICATION_STATE_CANCELLED);
  191.     }
  192. }
  193. ?>

Documentation generated on Mon, 11 Mar 2019 15:32:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.