From aca8ec33a85e0a70b818b6227145041717d7a69e Mon Sep 17 00:00:00 2001 From: mattab Date: Sun, 21 Jul 2013 17:01:35 +0900 Subject: Refs #4059 Work in progress: Conversion to use Namespaces: Period*, Metrics, Segment, SegmentExpression, PluginsManager. Removed some deprecated code. --- core/EventDispatcher.php | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) (limited to 'core/EventDispatcher.php') diff --git a/core/EventDispatcher.php b/core/EventDispatcher.php index 8496013cab..7c311e4dd4 100644 --- a/core/EventDispatcher.php +++ b/core/EventDispatcher.php @@ -9,11 +9,14 @@ * @package Piwik */ +namespace Piwik; +use Piwik\Plugin; + /** * This class allows code to post events from anywhere in Piwik and for * plugins to associate callbacks to be executed when events are posted. */ -class Piwik_EventDispatcher +class EventDispatcher { // implementation details for postEvent const EVENT_CALLBACK_GROUP_FIRST = 0; @@ -31,7 +34,7 @@ class Piwik_EventDispatcher public static function getInstance() { if (self::$instance === null) { - self::$instance = new Piwik_EventDispatcher(); + self::$instance = new EventDispatcher(); } return self::$instance; } @@ -66,7 +69,7 @@ class Piwik_EventDispatcher * loaded after the event is fired. * @param array|null $plugins The plugins to post events to. If null, the event * is posted to all plugins. The elements of this array - * can be either the Piwik_Plugin objects themselves + * can be either the Plugin objects themselves * or their string names. */ public function postEvent($eventName, $params, $pending = false, $plugins = null) @@ -76,7 +79,7 @@ class Piwik_EventDispatcher } if (empty($plugins)) { - $plugins = PluginsManager::getInstance()->getLoadedPlugins(); + $plugins = \Piwik\PluginsManager::getInstance()->getLoadedPlugins(); } $callbacks = array(); @@ -84,7 +87,7 @@ class Piwik_EventDispatcher // collect all callbacks to execute foreach ($plugins as $plugin) { if (is_string($plugin)) { - $plugin = PluginsManager::getInstance()->getLoadedPlugin($plugin); + $plugin = \Piwik\PluginsManager::getInstance()->getLoadedPlugin($plugin); } $hooks = $plugin->getListHooksRegistered(); @@ -150,7 +153,7 @@ class Piwik_EventDispatcher /** * Re-posts all pending events to the given plugin. * - * @param Piwik_Plugin $plugin + * @param Plugin $plugin */ public function postPendingEventsTo($plugin) { @@ -182,27 +185,3 @@ class Piwik_EventDispatcher } } -/** - * Post an event to the dispatcher which will notice the observers. - * - * @param string $eventName The event name. - * @param array $params The parameter array to forward to observer callbacks. - * @param bool $pending - * @param null $plugins - * @return void - */ -function Piwik_PostEvent($eventName, $params = array(), $pending = false, $plugins = null) -{ - Piwik_EventDispatcher::getInstance()->postEvent($eventName, $params, $pending, $plugins); -} - -/** - * Register an action to execute for a given event - * - * @param string $eventName Name of event - * @param callable $function Callback hook - */ -function Piwik_AddAction($eventName, $function) -{ - Piwik_EventDispatcher::getInstance()->addObserver($eventName, $function); -} -- cgit v1.2.3