File indexing completed on 2024-05-12 06:02:28

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_EventManager
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  */
0020 
0021 // require_once 'Zend/Stdlib/CallbackHandler.php';
0022 // require_once 'Zend/Stdlib/PriorityQueue.php';
0023 
0024 /**
0025  * Event manager: notification system
0026  *
0027  * Use the EventManager when you want to create a per-instance notification 
0028  * system for your objects.
0029  *
0030  * @category   Zend
0031  * @package    Zend_EventManager
0032  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0033  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0034  */
0035 class Zend_EventManager_GlobalEventManager
0036 {
0037     /**
0038      * @var Zend_EventManager_EventCollection
0039      */
0040     protected static $events;
0041 
0042     /**
0043      * Set the event collection on which this will operate
0044      * 
0045      * @param  null|Zend_EventManager_EventCollection $events 
0046      * @return void
0047      */
0048     public static function setEventCollection(Zend_EventManager_EventCollection $events = null)
0049     {
0050         self::$events = $events;
0051     }
0052 
0053     /**
0054      * Get event collection on which this operates
0055      *
0056      * @return Zend_EventManager_EventCollection
0057      */
0058     public static function getEventCollection()
0059     {
0060         if (null === self::$events) {
0061             self::setEventCollection(new Zend_EventManager_EventManager());
0062         }
0063         return self::$events;
0064     }
0065 
0066     /**
0067      * Trigger an event
0068      * 
0069      * @param  string $event 
0070      * @param  object|string $context 
0071      * @param  array|object $argv 
0072      * @return Zend_EventManager_ResponseCollection
0073      */
0074     public static function trigger($event, $context, $argv = array())
0075     {
0076         return self::getEventCollection()->trigger($event, $context, $argv);
0077     }
0078 
0079     /**
0080      * Trigger listeenrs until return value of one causes a callback to evaluate 
0081      * to true.
0082      * 
0083      * @param  string $event 
0084      * @param  string|object $context 
0085      * @param  array|object $argv 
0086      * @param  callback $callback 
0087      * @return Zend_EventManager_ResponseCollection
0088      */
0089     public static function triggerUntil($event, $context, $argv, $callback)
0090     {
0091         return self::getEventCollection()->triggerUntil($event, $context, $argv, $callback);
0092     }
0093 
0094     /**
0095      * Attach a listener to an event
0096      * 
0097      * @param  string $event 
0098      * @param  callback $callback 
0099      * @param  int $priority 
0100      * @return Zend_Stdlib_CallbackHandler
0101      */
0102     public static function attach($event, $callback, $priority = 1)
0103     {
0104         return self::getEventCollection()->attach($event, $callback, $priority);
0105     }
0106 
0107     /**
0108      * Detach a callback from a listener
0109      * 
0110      * @param  Zend_Stdlib_CallbackHandler $listener 
0111      * @return bool
0112      */
0113     public static function detach(Zend_Stdlib_CallbackHandler $listener)
0114     {
0115         return self::getEventCollection()->detach($listener);
0116     }
0117 
0118     /**
0119      * Retrieve list of events this object manages
0120      * 
0121      * @return array
0122      */
0123     public static function getEvents()
0124     {
0125         return self::getEventCollection()->getEvents();
0126     }
0127 
0128     /**
0129      * Retrieve all listeners for a given event
0130      * 
0131      * @param  string $event 
0132      * @return Zend_Stdlib_PriorityQueue|array
0133      */
0134     public static function getListeners($event)
0135     {
0136         return self::getEventCollection()->getListeners($event);
0137     }
0138 
0139     /**
0140      * Clear all listeners for a given event
0141      * 
0142      * @param  string $event 
0143      * @return void
0144      */
0145     public static function clearListeners($event)
0146     {
0147         return self::getEventCollection()->clearListeners($event);
0148     }
0149 }