public function registerPlugin(AbstractPlugin $plugin, $stackIndex = null)
{
if (false !== array_search($plugin, $this->_plugins, true)) {
throw new \Exception('Plugin already registered');
}
//installed?
if (!$plugin::isInstalled()) {
if (is_object($plugin)) {
$className = get_class($plugin);
Logger::debug("Not registering plugin [ " . $className . " ] because it is not installed");
} else {
Logger::debug("Not registering plugin, it is not an object");
}
return $this;
}
$stackIndex = (int) $stackIndex;
if ($stackIndex) {
if (isset($this->_plugins[$stackIndex])) {
throw new \Exception('Plugin with stackIndex "' . $stackIndex . '" already registered');
}
$this->_plugins[$stackIndex] = $plugin;
} else {
$stackIndex = count($this->_plugins);
while (isset($this->_plugins[$stackIndex])) {
++$stackIndex;
}
$this->_plugins[$stackIndex] = $plugin;
}
ksort($this->_plugins);
$plugin->init();
return $this;
}