API16:JDispatcher/trigger
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Triggers an event by dispatching arguments to all observers that handle the event and returning their return values.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
trigger($event, $args=array())
| Parameter Name | Default Value | Description |
|---|---|---|
| $event | $event The event to trigger. | |
| $args | array() | $args An array of arguments. |
Returns
array An array of results from each function call.
Defined in
libraries/joomla/event/dispatcher.php
Importing
jimport( 'joomla.event.dispatcher' );
Source Body
public function trigger($event, $args = array()) { // Initialise variables. $result = array(); /* * If no arguments were passed, we still need to pass an empty array to * the call_user_func_array function. */ if (!is_array($args)) { $args = (array)$args; } $event = strtolower($event); // Check if any plugins are attached to the event. if (!isset($this->_methods[$event]) || empty($this->_methods[$event])) { // No Plugins Associated To Event! return $result; } // Loop through all plugins having a method matching our event foreach ($this->_methods[$event] AS $key) { // Check if the plugin is present. if (!isset($this->_observers[$key])) { continue; } // Fire the event for an object based observer. if (is_object($this->_observers[$key])) { $args['event'] = $event; $result[] = $this->_observers[$key]->update($args); } // Fire the event for a function based observer. elseif (is_array($this->_observers[$key])) { $result[] = call_user_func_array($this->_observers[$key]['handler'], $args); } } return $result; }
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />
