Source code for file /joomla/application/event.php
Documentation is available at event.php
* @version $Id: event.php 6678 2007-02-19 09:06:14Z louis $
* @package Joomla.Framework
* @subpackage Application
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* Class to handle dispatching of events.
* This is the Observable part of the Observer design pattern
* for the plugin architecture.
* @package Joomla.Framework
* @subpackage Application
* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:plugins/ Plugins tutorial
* Returns a reference to the global Event Dispatcher object, only creating it
* if it doesn't already exist.
* This method must be invoked as:
* <pre> $dispatcher = &JEventDispatcher::getInstance();</pre>
* @return JEventDispatcher The EventDispatcher object.
* Registers an event handler to the event dispatcher
* @param string $event Name of the event to register handler for
* @param string $handler Name of the event handler
// Are we dealing with a class or function type handler?
// Ok, function type event handler... lets attach it.
$method =
array ('event' =>
$event, 'handler' =>
$handler);
//Ok, class type event handler... lets instantiate and attach it.
$this->attach(new $handler($this));
JError::raiseWarning('SOME_ERROR_CODE', 'JEventDispatcher::register: Event handler not recognized.', 'Handler: '.
$handler );
* Triggers an event by dispatching arguments to all observers that handle
* the event and returning their return values.
* @param string $event The event name
* @param array $args An array of arguments
* @param boolean $doUnpublished [DEPRECATED]
* @return array An array of results from each function call
function trigger($event, $args =
null, $doUnpublished =
false)
* If no arguments were passed, we still need to pass an empty array to
* the call_user_func_array function.
* We need to iterate through all of the registered observers and
* trigger the event for each observer that handles the event.
foreach ($this->_observers as $observer)
* Since we have gotten here, we know a little something about
* the observer. It is a function type observer... lets see if
if ($observer['event'] ==
$event)
* Couldn't find the function that the observer specified..
* wierd, lets throw an error.
JError::raiseWarning('SOME_ERROR_CODE', 'JEventDispatcher::trigger: Event Handler Method does not exist.', 'Method called: '.
$observer['handler']);
// Handler doesn't handle this event, move on to next observer.
* Since we have gotten here, we know a little something about
* the observer. It is a class type observer... lets see if it
* is an object which has an update method.
* Ok, now we know that the observer is both not an array
* and IS an object. Lets trigger its update method if it
* handles the event and return any results.
$result[] =
$observer->update($args);
* Handler doesn't handle this event, move on to next
* At this point, we know that the registered observer is
* neither a function type observer nor an object type
* observer. PROBLEM, lets throw an error.
JError::raiseWarning('SOME_ERROR_CODE', 'JEventDispatcher::trigger: Unknown Event Handler.', $observer );