PHP Класс Event_Dispatcher, newscoop

The Event_Dispatcher acts acts as a notification dispatch table. It is used to notify other objects of interesting things, if they meet certain criteria. This information is encapsulated in {@link Event_Notification} objects. Client objects register themselves with the Event_Dispatcher as observers of specific notifications posted by other objects. When an event occurs, an object posts an appropriate notification to the Event_Dispatcher. The Event_Dispatcher dispatches a message to each registered observer, passing the notification as the sole argument. The Event_Dispatcher is actually a combination of three design patterns: the Singleton, {@link http://c2.com/cgi/wiki?MediatorPattern Mediator}, and Observer patterns. The idea behind Event_Dispatcher is borrowed from {@link http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/index.html Apple's Cocoa framework}.
Автор: Bertrand Mansion ([email protected])
Автор: Stephan Schmidt ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$_name string Name of the dispatcher
$_nestedDispatchers array Nested observers
$_notificationClass string Class used for notifications
$_pending array Pending notifications
$_ro array Registered observer callbacks

Открытые методы

Метод Описание
Event_Dispatcher ( $name ) PHP4 constructor
__construct ( $name ) PHP5 constructor
addNestedDispatcher ( &$dispatcher ) add a new nested dispatcher
addObserver ( $callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null ) : void Registers an observer callback
getInstance ( $name = '__default' ) : object Returns a notification dispatcher singleton
getName ( ) : string Get the name of the dispatcher.
getObservers ( $nName = EVENT_DISPATCHER_GLOBAL, $class = null ) : array Get all observers, that have been registered for a notification
observerRegistered ( $callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null ) : boolean Check, whether the specified observer has been registered with the dispatcher
post ( &$object, $nName, $info = [], $pending = true, $bubble = true ) : object Creates and posts a notification object
postNotification ( &$notification, $pending = true, $bubble = true ) : object Posts the {@link Event_Notification} object
removeNestedDispatcher ( $dispatcher ) : boolean remove a nested dispatcher
removeObserver ( $callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null ) : boolean Removes a registered observer that correspond to the given criteria
setNotificationClass ( $class ) : boolean Changes the class used for notifications

Описание методов

Event_Dispatcher() публичный метод

Please use {@link getInstance()} instead.
public Event_Dispatcher ( $name )

__construct() публичный метод

Please use {@link getInstance()} instead.
public __construct ( $name )

addNestedDispatcher() публичный метод

Notifications will be broadcasted to this dispatcher as well, which allows you to create event bubbling.
public addNestedDispatcher ( &$dispatcher )

addObserver() публичный метод

This method registers a {@link http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback callback} which is called when the notification corresponding to the criteria given at registration time is posted. The criteria are the notification name and eventually the class of the object posted with the notification. If there are any pending notifications corresponding to the criteria given here, the callback will be called straight away. If the notification name is empty, the observer will receive all the posted notifications. Same goes for the class name.
public addObserver ( $callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null ) : void
Результат void

getInstance() публичный метод

There is usually no need to have more than one notification center for an application so this is the recommended way to get a Event_Dispatcher object.
public getInstance ( $name = '__default' ) : object
Результат object Event_Dispatcher

getName() публичный метод

The name is the unique identifier of a dispatcher.
public getName ( ) : string
Результат string name of the dispatcher

getObservers() публичный метод

Get all observers, that have been registered for a notification
public getObservers ( $nName = EVENT_DISPATCHER_GLOBAL, $class = null ) : array
Результат array List of all observers

observerRegistered() публичный метод

Check, whether the specified observer has been registered with the dispatcher
public observerRegistered ( $callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null ) : boolean
Результат boolean True if the observer has been registered, false otherwise

post() публичный метод

The purpose of the optional associated object is generally to pass the object posting the notification to the observers, so that the observers can query the posting object for more information about the event. Notifications are by default added to a pending notification list. This way, if an observer is not registered by the time they are posted, it will still be notified when it is added as an observer. This behaviour can be turned off in order to make sure that only the registered observers will be notified. The info array serves as a container for any kind of useful information. It is added to the notification object and posted along.
public post ( &$object, $nName, $info = [], $pending = true, $bubble = true ) : object
Результат object The notification object

postNotification() публичный метод

Posts the {@link Event_Notification} object
См. также: Event_Dispatcher::post()
public postNotification ( &$notification, $pending = true, $bubble = true ) : object
Результат object The notification object

removeNestedDispatcher() публичный метод

remove a nested dispatcher
public removeNestedDispatcher ( $dispatcher ) : boolean
Результат boolean

removeObserver() публичный метод

Removes a registered observer that correspond to the given criteria
public removeObserver ( $callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null ) : boolean
Результат boolean True if an observer was removed, false otherwise

setNotificationClass() публичный метод

You may call this method on an object to change it for a single dispatcher or statically, to set the default for all dispatchers that will be created.
public setNotificationClass ( $class ) : boolean
Результат boolean

Описание свойств

$_name публичное свойство

Name of the dispatcher
public string $_name
Результат string

$_nestedDispatchers публичное свойство

Nested observers
public array $_nestedDispatchers
Результат array

$_notificationClass публичное свойство

Class used for notifications
public string $_notificationClass
Результат string

$_pending публичное свойство

Pending notifications
public array $_pending
Результат array

$_ro публичное свойство

Registered observer callbacks
public array $_ro
Результат array