web/lib/Zend/EventManager/GlobalEventManager.php
changeset 808 6b6c2214f778
child 1230 68c69c656a2c
equal deleted inserted replaced
807:877f952ae2bd 808:6b6c2214f778
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_EventManager
       
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  */
       
    20 
       
    21 require_once 'Zend/Stdlib/CallbackHandler.php';
       
    22 require_once 'Zend/Stdlib/PriorityQueue.php';
       
    23 
       
    24 /**
       
    25  * Event manager: notification system
       
    26  *
       
    27  * Use the EventManager when you want to create a per-instance notification 
       
    28  * system for your objects.
       
    29  *
       
    30  * @category   Zend
       
    31  * @package    Zend_EventManager
       
    32  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
       
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    34  */
       
    35 class Zend_EventManager_GlobalEventManager
       
    36 {
       
    37     /**
       
    38      * @var Zend_EventManager_EventCollection
       
    39      */
       
    40     protected static $events;
       
    41 
       
    42     /**
       
    43      * Set the event collection on which this will operate
       
    44      * 
       
    45      * @param  null|Zend_EventManager_EventCollection $events 
       
    46      * @return void
       
    47      */
       
    48     public static function setEventCollection(Zend_EventManager_EventCollection $events = null)
       
    49     {
       
    50         self::$events = $events;
       
    51     }
       
    52 
       
    53     /**
       
    54      * Get event collection on which this operates
       
    55      * 
       
    56      * @return void
       
    57      */
       
    58     public static function getEventCollection()
       
    59     {
       
    60         if (null === self::$events) {
       
    61             self::setEventCollection(new Zend_EventManager_EventManager());
       
    62         }
       
    63         return self::$events;
       
    64     }
       
    65 
       
    66     /**
       
    67      * Trigger an event
       
    68      * 
       
    69      * @param  string $event 
       
    70      * @param  object|string $context 
       
    71      * @param  array|object $argv 
       
    72      * @return Zend_EventManager_ResponseCollection
       
    73      */
       
    74     public static function trigger($event, $context, $argv = array())
       
    75     {
       
    76         return self::getEventCollection()->trigger($event, $context, $argv);
       
    77     }
       
    78 
       
    79     /**
       
    80      * Trigger listeenrs until return value of one causes a callback to evaluate 
       
    81      * to true.
       
    82      * 
       
    83      * @param  string $event 
       
    84      * @param  string|object $context 
       
    85      * @param  array|object $argv 
       
    86      * @param  callback $callback 
       
    87      * @return Zend_EventManager_ResponseCollection
       
    88      */
       
    89     public static function triggerUntil($event, $context, $argv, $callback)
       
    90     {
       
    91         return self::getEventCollection()->triggerUntil($event, $context, $argv, $callback);
       
    92     }
       
    93 
       
    94     /**
       
    95      * Attach a listener to an event
       
    96      * 
       
    97      * @param  string $event 
       
    98      * @param  callback $callback 
       
    99      * @param  int $priority 
       
   100      * @return Zend_Stdlib_CallbackHandler
       
   101      */
       
   102     public static function attach($event, $callback, $priority = 1)
       
   103     {
       
   104         return self::getEventCollection()->attach($event, $callback, $priority);
       
   105     }
       
   106 
       
   107     /**
       
   108      * Detach a callback from a listener
       
   109      * 
       
   110      * @param  Zend_Stdlib_CallbackHandler $listener 
       
   111      * @return bool
       
   112      */
       
   113     public static function detach(Zend_Stdlib_CallbackHandler $listener)
       
   114     {
       
   115         return self::getEventCollection()->detach($listener);
       
   116     }
       
   117 
       
   118     /**
       
   119      * Retrieve list of events this object manages
       
   120      * 
       
   121      * @return array
       
   122      */
       
   123     public static function getEvents()
       
   124     {
       
   125         return self::getEventCollection()->getEvents();
       
   126     }
       
   127 
       
   128     /**
       
   129      * Retrieve all listeners for a given event
       
   130      * 
       
   131      * @param  string $event 
       
   132      * @return Zend_Stdlib_PriorityQueue|array
       
   133      */
       
   134     public static function getListeners($event)
       
   135     {
       
   136         return self::getEventCollection()->getListeners($event);
       
   137     }
       
   138 
       
   139     /**
       
   140      * Clear all listeners for a given event
       
   141      * 
       
   142      * @param  string $event 
       
   143      * @return void
       
   144      */
       
   145     public static function clearListeners($event)
       
   146     {
       
   147         return self::getEventCollection()->clearListeners($event);
       
   148     }
       
   149 }