Varien_Event_Collection Class Reference

List of all members.

Public Member Functions

 __construct ()
 getAllEvents ()
 getGlobalObservers ()
 getEventByName ($eventName)
 addEvent (Varien_Event $event)
 addObserver (Varien_Event_Observer $observer)
 dispatch ($eventName, array $data=array())

Protected Attributes

 $_events
 $_observers


Detailed Description

Definition at line 35 of file Collection.php.


Constructor & Destructor Documentation

__construct (  ) 

Initializes global observers collection

Definition at line 57 of file Collection.php.

00058     {
00059         $this->_events = array();
00060         $this->_globalObservers = new Varien_Event_Observer_Collection();
00061     }


Member Function Documentation

addEvent ( Varien_Event event  ) 

Register an event for this collection

Parameters:
Varien_Event $event
Returns:
Varien_Event_Collection

Definition at line 105 of file Collection.php.

00106     {
00107         $this->_events[$event->getName()] = $event;
00108         return $this;
00109     }

addObserver ( Varien_Event_Observer observer  ) 

Register an observer

If observer has event_name property it will be regitered for this specific event. If not it will be registered as global observer

Parameters:
Varien_Event_Observer $observer
Returns:
Varien_Event_Collection

Definition at line 120 of file Collection.php.

00121     {
00122         $eventName = $observer->getEventName();
00123         if ($eventName) {
00124             $this->getEventByName($eventName)->addObserver($observer);
00125         } else {
00126             $this->getGlobalObservers()->addObserver($observer);
00127         }
00128         return $this;
00129     }

dispatch ( eventName,
array data = array() 
)

Dispatch event name with optional data

Will dispatch specific event and will try all global observers

Parameters:
string $eventName
array $data
Returns:
Varien_Event_Collection

Definition at line 140 of file Collection.php.

00141     {
00142         $event = $this->getEventByName($eventName);
00143         $event->addData($data)->dispatch();
00144         $this->getGlobalObservers()->dispatch($event);
00145         return $this;
00146     }

getAllEvents (  ) 

Returns all registered events in collection

Returns:
array

Definition at line 68 of file Collection.php.

00069     {
00070         return $this->_events;
00071     }

getEventByName ( eventName  ) 

Returns event by its name

If event doesn't exist creates new one and returns it

Parameters:
string $eventName
Returns:
Varien_Event

Definition at line 91 of file Collection.php.

00092     {
00093         if (!isset($this->_events[$eventName])) {
00094             $this->addEvent(new Varien_Event(array('name'=>$eventName)));
00095         }
00096         return $this->_events[$eventName];
00097     }

getGlobalObservers (  ) 

Returns all registered global observers for the collection of events

Returns:
Varien_Event_Observer_Collection

Definition at line 78 of file Collection.php.

00079     {
00080         return $this->_globalObservers;
00081     }


Member Data Documentation

$_events [protected]

Definition at line 42 of file Collection.php.

$_observers [protected]

Definition at line 51 of file Collection.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:25:01 2009 for Magento by  doxygen 1.5.8