diff options
author | diosmosis <benakamoorthi@fastmail.fm> | 2014-08-25 07:00:23 +0400 |
---|---|---|
committer | diosmosis <benakamoorthi@fastmail.fm> | 2014-08-25 07:00:23 +0400 |
commit | a8c016e176db0c4f76e01a347e3328b6f3e50639 (patch) | |
tree | 18bd711fe3919d55deb4ef3c9589d9d479e6b10a /core/EventDispatcher.php | |
parent | d63595290a25f1920ba60f7aeafbd8e9e9f0b32e (diff) |
Allow PluginManager to be injected in EventDispatcher instance for PiwikDebugger functionality.
Diffstat (limited to 'core/EventDispatcher.php')
-rw-r--r-- | core/EventDispatcher.php | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/core/EventDispatcher.php b/core/EventDispatcher.php index b902bdef2c..ac6f6d1ef0 100644 --- a/core/EventDispatcher.php +++ b/core/EventDispatcher.php @@ -46,6 +46,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. * * @param string $eventName The name of the event, ie, API.getReportMetadata. @@ -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 |