Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-10-08 09:24:28 +0400
committermattab <matthieu.aubry@gmail.com>2013-10-08 09:24:28 +0400
commit1fa8da9b963e99e08c829fe6491e8ccf2d1054e2 (patch)
tree137c50850a5f21f1651f8066d4bd381a661e1987 /core/EventDispatcher.php
parentfcbef99dbf93df94ff5ed4cfaa5eeebfcf4aac14 (diff)
Applying phpstorm code style PSR refs #3771
Diffstat (limited to 'core/EventDispatcher.php')
-rw-r--r--core/EventDispatcher.php53
1 files changed, 27 insertions, 26 deletions
diff --git a/core/EventDispatcher.php b/core/EventDispatcher.php
index 5122250b08..6f3556a11c 100644
--- a/core/EventDispatcher.php
+++ b/core/EventDispatcher.php
@@ -10,6 +10,7 @@
*/
namespace Piwik;
+
use Piwik\Plugin;
/**
@@ -22,12 +23,12 @@ class EventDispatcher
const EVENT_CALLBACK_GROUP_FIRST = 0;
const EVENT_CALLBACK_GROUP_SECOND = 1;
const EVENT_CALLBACK_GROUP_THIRD = 2;
-
+
/**
* Singleton instance.
*/
private static $instance = null;
-
+
/**
* Returns the singleton EventDispatcher instance. Creates it if necessary.
*/
@@ -38,31 +39,31 @@ class EventDispatcher
}
return self::$instance;
}
-
+
/**
* Array of observers (callbacks attached to events) that are not methods
* of plugin classes.
- *
+ *
* @var array
*/
private $extraObservers = array();
-
+
/**
* Array storing information for all pending events. Each item in the array
* will be an array w/ two elements:
- *
+ *
* array(
* 'Event.Name', // the event name
* array('event', 'parameters') // the parameters to pass to event observers
* )
- *
+ *
* @var array
*/
private $pendingEvents = array();
-
+
/**
* Triggers an event, executing all callbacks associated with it.
- *
+ *
* @param string $eventName The name of the event, ie, API.getReportMetadata.
* @param array $params The parameters to pass to each callback when executing.
* @param bool $pending Whether this event should be posted again for plugins
@@ -77,36 +78,36 @@ class EventDispatcher
if ($pending) {
$this->pendingEvents[] = array($eventName, $params);
}
-
+
if (empty($plugins)) {
$plugins = PluginsManager::getInstance()->getLoadedPlugins();
}
-
+
$callbacks = array();
-
+
// collect all callbacks to execute
foreach ($plugins as $plugin) {
if (is_string($plugin)) {
$plugin = PluginsManager::getInstance()->getLoadedPlugin($plugin);
}
-
+
$hooks = $plugin->getListHooksRegistered();
-
+
if (isset($hooks[$eventName])) {
list($pluginFunction, $callbackGroup) = $this->getCallbackFunctionAndGroupNumber($hooks[$eventName]);
-
+
$callbacks[$callbackGroup][] = array($plugin, $pluginFunction);
}
}
-
+
if (isset($this->extraObservers[$eventName])) {
foreach ($this->extraObservers[$eventName] as $callbackInfo) {
list($callback, $callbackGroup) = $this->getCallbackFunctionAndGroupNumber($callbackInfo);
-
+
$callbacks[$callbackGroup][] = $callback;
}
}
-
+
// execute callbacks in order
foreach ($callbacks as $callbackGroup) {
foreach ($callbackGroup as $callback) {
@@ -114,11 +115,11 @@ class EventDispatcher
}
}
}
-
+
/**
* Associates a callback that is not a plugin class method with an event
* name.
- *
+ *
* @param string $eventName
* @param array|callable $callback This can be a normal PHP callback or an array
* that looks like this:
@@ -139,20 +140,20 @@ class EventDispatcher
{
$this->extraObservers[$eventName][] = $callback;
}
-
+
/**
* Removes all registered observers for an event name. Only used for testing.
- *
+ *
* @param string $eventName
*/
public function clearObservers($eventName)
{
$this->extraObservers[$eventName] = array();
}
-
+
/**
* Re-posts all pending events to the given plugin.
- *
+ *
* @param Plugin $plugin
*/
public function postPendingEventsTo($plugin)
@@ -162,7 +163,7 @@ class EventDispatcher
$this->postEvent($eventName, $eventParams, $pending = false, array($plugin));
}
}
-
+
private function getCallbackFunctionAndGroupNumber($hookInfo)
{
if (is_array($hookInfo)
@@ -180,7 +181,7 @@ class EventDispatcher
$pluginFunction = $hookInfo;
$callbackGroup = self::EVENT_CALLBACK_GROUP_SECOND;
}
-
+
return array($pluginFunction, $callbackGroup);
}
}