update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -9,16 +9,22 @@
|
|||
|
||||
namespace Piwik;
|
||||
|
||||
use Piwik\Plugin;
|
||||
use Piwik\Container\StaticContainer;
|
||||
|
||||
/**
|
||||
* This class allows code to post events from anywhere in Piwik and for
|
||||
* plugins to associate callbacks to be executed when events are posted.
|
||||
*
|
||||
* @method static \Piwik\EventDispatcher getInstance()
|
||||
*/
|
||||
class EventDispatcher extends Singleton
|
||||
class EventDispatcher
|
||||
{
|
||||
/**
|
||||
* @return EventDispatcher
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
return StaticContainer::get('Piwik\EventDispatcher');
|
||||
}
|
||||
|
||||
// implementation details for postEvent
|
||||
const EVENT_CALLBACK_GROUP_FIRST = 0;
|
||||
const EVENT_CALLBACK_GROUP_SECOND = 1;
|
||||
|
|
@ -45,6 +51,28 @@ class EventDispatcher extends Singleton
|
|||
*/
|
||||
private $pendingEvents = array();
|
||||
|
||||
/**
|
||||
* Plugin\Manager instance used to get list of loaded plugins.
|
||||
*
|
||||
* @var \Piwik\Plugin\Manager
|
||||
*/
|
||||
private $pluginManager;
|
||||
|
||||
private $pluginHooks = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct(Plugin\Manager $pluginManager, array $observers = array())
|
||||
{
|
||||
$this->pluginManager = $pluginManager;
|
||||
|
||||
foreach ($observers as $observerInfo) {
|
||||
list($eventName, $callback) = $observerInfo;
|
||||
$this->extraObservers[$eventName][] = $callback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers an event, executing all callbacks associated with it.
|
||||
*
|
||||
|
|
@ -63,24 +91,36 @@ class EventDispatcher extends Singleton
|
|||
$this->pendingEvents[] = array($eventName, $params);
|
||||
}
|
||||
|
||||
$manager = $this->pluginManager;
|
||||
|
||||
if (empty($plugins)) {
|
||||
$plugins = \Piwik\Plugin\Manager::getInstance()->getPluginsLoadedAndActivated();
|
||||
$plugins = $manager->getPluginsLoadedAndActivated();
|
||||
}
|
||||
|
||||
$callbacks = array();
|
||||
|
||||
// collect all callbacks to execute
|
||||
foreach ($plugins as $plugin) {
|
||||
if (is_string($plugin)) {
|
||||
$plugin = \Piwik\Plugin\Manager::getInstance()->getLoadedPlugin($plugin);
|
||||
foreach ($plugins as $pluginName) {
|
||||
if (!is_string($pluginName)) {
|
||||
$pluginName = $pluginName->getPluginName();
|
||||
}
|
||||
|
||||
$hooks = $plugin->getListHooksRegistered();
|
||||
if (!isset($this->pluginHooks[$pluginName])) {
|
||||
$plugin = $manager->getLoadedPlugin($pluginName);
|
||||
$this->pluginHooks[$pluginName] = $plugin->getListHooksRegistered();
|
||||
}
|
||||
|
||||
$hooks = $this->pluginHooks[$pluginName];
|
||||
|
||||
if (isset($hooks[$eventName])) {
|
||||
list($pluginFunction, $callbackGroup) = $this->getCallbackFunctionAndGroupNumber($hooks[$eventName]);
|
||||
|
||||
$callbacks[$callbackGroup][] = is_string($pluginFunction) ? array($plugin, $pluginFunction) : $pluginFunction;
|
||||
if (is_string($pluginFunction)) {
|
||||
$plugin = $manager->getLoadedPlugin($pluginName);
|
||||
$callbacks[$callbackGroup][] = array($plugin, $pluginFunction) ;
|
||||
} else {
|
||||
$callbacks[$callbackGroup][] = $pluginFunction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,6 +132,9 @@ class EventDispatcher extends Singleton
|
|||
}
|
||||
}
|
||||
|
||||
// sort callbacks by their importance
|
||||
ksort($callbacks);
|
||||
|
||||
// execute callbacks in order
|
||||
foreach ($callbacks as $callbackGroup) {
|
||||
foreach ($callbackGroup as $callback) {
|
||||
|
|
@ -125,30 +168,6 @@ class EventDispatcher extends Singleton
|
|||
$this->extraObservers[$eventName][] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all registered extra observers for an event name. Only used for testing.
|
||||
*
|
||||
* @param string $eventName
|
||||
*/
|
||||
public function clearObservers($eventName)
|
||||
{
|
||||
$this->extraObservers[$eventName] = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all registered extra observers. Only used for testing.
|
||||
*/
|
||||
public function clearAllObservers()
|
||||
{
|
||||
foreach ($this->extraObservers as $eventName => $eventObservers) {
|
||||
if (strpos($eventName, 'Log.format') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->extraObservers[$eventName] = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-posts all pending events to the given plugin.
|
||||
*
|
||||
|
|
@ -170,10 +189,10 @@ class EventDispatcher extends Singleton
|
|||
$pluginFunction = $hookInfo['function'];
|
||||
if (!empty($hookInfo['before'])) {
|
||||
$callbackGroup = self::EVENT_CALLBACK_GROUP_FIRST;
|
||||
} else if (!empty($hookInfo['after'])) {
|
||||
$callbackGroup = self::EVENT_CALLBACK_GROUP_SECOND;
|
||||
} else {
|
||||
} elseif (!empty($hookInfo['after'])) {
|
||||
$callbackGroup = self::EVENT_CALLBACK_GROUP_THIRD;
|
||||
} else {
|
||||
$callbackGroup = self::EVENT_CALLBACK_GROUP_SECOND;
|
||||
}
|
||||
} else {
|
||||
$pluginFunction = $hookInfo;
|
||||
|
|
@ -183,4 +202,3 @@ class EventDispatcher extends Singleton
|
|||
return array($pluginFunction, $callbackGroup);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue