From a8c016e176db0c4f76e01a347e3328b6f3e50639 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Sun, 24 Aug 2014 20:00:23 -0700 Subject: Allow PluginManager to be injected in EventDispatcher instance for PiwikDebugger functionality. --- core/EventDispatcher.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'core/EventDispatcher.php') diff --git a/core/EventDispatcher.php b/core/EventDispatcher.php index b902bdef2c..ac6f6d1ef0 100644 --- a/core/EventDispatcher.php +++ b/core/EventDispatcher.php @@ -45,6 +45,25 @@ class EventDispatcher extends Singleton */ private $pendingEvents = array(); + /** + * Plugin\Manager instance used to get list of loaded plugins. + * + * @var Piwik\Plugin\Manager + */ + private $pluginManager; + + /** + * Constructor. + */ + public function __construct($pluginManager = null) + { + if ($pluginManager === null) { + $pluginManager = \Piwik\Plugin\Manager::getInstance(); + } + + $this->pluginManager = $pluginManager; + } + /** * Triggers an event, executing all callbacks associated with it. * @@ -64,7 +83,7 @@ class EventDispatcher extends Singleton } if (empty($plugins)) { - $plugins = \Piwik\Plugin\Manager::getInstance()->getPluginsLoadedAndActivated(); + $plugins = $this->pluginManager->getPluginsLoadedAndActivated(); } $callbacks = array(); @@ -72,7 +91,7 @@ class EventDispatcher extends Singleton // collect all callbacks to execute foreach ($plugins as $plugin) { if (is_string($plugin)) { - $plugin = \Piwik\Plugin\Manager::getInstance()->getLoadedPlugin($plugin); + $plugin = $this->pluginManager->getLoadedPlugin($plugin); } $hooks = $plugin->getListHooksRegistered(); @@ -94,6 +113,7 @@ class EventDispatcher extends Singleton // sort callbacks by their importance ksort($callbacks); + // execute callbacks in order foreach ($callbacks as $callbackGroup) { foreach ($callbackGroup as $callback) { @@ -183,5 +203,4 @@ class EventDispatcher extends Singleton return array($pluginFunction, $callbackGroup); } -} - +} \ No newline at end of file -- cgit v1.2.3