mirror of
https://github.com/Mibew/tray.git
synced 2025-01-22 18:10:34 +03:00
Replaced plugin interface to plugin abstract class
This commit is contained in:
parent
3f95a395c8
commit
69695e5c3f
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Test plugin for PHPUnit tests
|
||||
*/
|
||||
Class Phpunit_autotest_plugin_managerPlugin implements Plugin{
|
||||
Class Phpunit_autotest_plugin_managerPlugin extends Plugin{
|
||||
|
||||
public $eventsRegistered = false;
|
||||
public $listenersRegistered = false;
|
||||
@ -32,6 +32,10 @@ Class Phpunit_autotest_plugin_managerPlugin implements Plugin{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public function __construct(){
|
||||
$this->initialized = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -16,9 +16,22 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base plugin interface
|
||||
* Base plugin class
|
||||
*/
|
||||
interface Plugin {
|
||||
abstract Class Plugin {
|
||||
|
||||
/**
|
||||
* Constructor must set this value to true after successful initialization
|
||||
* failures
|
||||
* @var boolean
|
||||
*/
|
||||
public $initialized = false;
|
||||
|
||||
/**
|
||||
* An array of plugin configuration
|
||||
* @var array
|
||||
*/
|
||||
public static $config = array();
|
||||
|
||||
/**
|
||||
* Returns plugin weight. Weight is used for determine loading order and as default
|
||||
@ -26,17 +39,17 @@ interface Plugin {
|
||||
*
|
||||
* @return int Plugin weight
|
||||
*/
|
||||
public function getWeight();
|
||||
abstract public function getWeight();
|
||||
|
||||
/**
|
||||
* Register events
|
||||
*/
|
||||
public function registerEvents();
|
||||
abstract public function registerEvents();
|
||||
|
||||
/**
|
||||
* Register listeners
|
||||
*/
|
||||
public function registerListeners();
|
||||
abstract public function registerListeners();
|
||||
|
||||
}
|
||||
|
||||
|
@ -67,19 +67,26 @@ Class PluginManager {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
// Check if plugin implements 'Plugin' interface
|
||||
if (! in_array('Plugin', class_implements($plugin_classname))) {
|
||||
// Check if plugin extends abstract 'Plugin' class
|
||||
if ('Plugin' != get_parent_class($plugin_classname)) {
|
||||
trigger_error(
|
||||
"Plugin class '{$plugin_classname}' does not implement " .
|
||||
"'Plugin' interface!",
|
||||
"Plugin class '{$plugin_classname}' does not extend " .
|
||||
"abstract 'Plugin' class!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
continue;
|
||||
}
|
||||
// Add plugin to loading queue
|
||||
$plugin_instance = new $plugin_classname($plugin_config);
|
||||
if ($plugin_instance->initialized) {
|
||||
$loading_queue[$plugin_instance->getWeight() . "_" . $offset] = $plugin_instance;
|
||||
$offset++;
|
||||
} else {
|
||||
trigger_error(
|
||||
"Plugin '{$plugin_name}' does not initialized correctly!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
}
|
||||
}
|
||||
// Sort queue in order to plugins' weights
|
||||
uksort($loading_queue, 'strnatcmp');
|
||||
|
Loading…
Reference in New Issue
Block a user