mirror of
https://github.com/Mibew/design.git
synced 2025-01-23 02:20: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
|
* Test plugin for PHPUnit tests
|
||||||
*/
|
*/
|
||||||
Class Phpunit_autotest_plugin_managerPlugin implements Plugin{
|
Class Phpunit_autotest_plugin_managerPlugin extends Plugin{
|
||||||
|
|
||||||
public $eventsRegistered = false;
|
public $eventsRegistered = false;
|
||||||
public $listenersRegistered = false;
|
public $listenersRegistered = false;
|
||||||
@ -32,6 +32,10 @@ Class Phpunit_autotest_plugin_managerPlugin implements Plugin{
|
|||||||
throw new Exception();
|
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
|
* Returns plugin weight. Weight is used for determine loading order and as default
|
||||||
@ -26,17 +39,17 @@ interface Plugin {
|
|||||||
*
|
*
|
||||||
* @return int Plugin weight
|
* @return int Plugin weight
|
||||||
*/
|
*/
|
||||||
public function getWeight();
|
abstract public function getWeight();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register events
|
* Register events
|
||||||
*/
|
*/
|
||||||
public function registerEvents();
|
abstract public function registerEvents();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register listeners
|
* Register listeners
|
||||||
*/
|
*/
|
||||||
public function registerListeners();
|
abstract public function registerListeners();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,19 +67,26 @@ Class PluginManager {
|
|||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Check if plugin implements 'Plugin' interface
|
// Check if plugin extends abstract 'Plugin' class
|
||||||
if (! in_array('Plugin', class_implements($plugin_classname))) {
|
if ('Plugin' != get_parent_class($plugin_classname)) {
|
||||||
trigger_error(
|
trigger_error(
|
||||||
"Plugin class '{$plugin_classname}' does not implement " .
|
"Plugin class '{$plugin_classname}' does not extend " .
|
||||||
"'Plugin' interface!",
|
"abstract 'Plugin' class!",
|
||||||
E_USER_WARNING
|
E_USER_WARNING
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Add plugin to loading queue
|
// Add plugin to loading queue
|
||||||
$plugin_instance = new $plugin_classname($plugin_config);
|
$plugin_instance = new $plugin_classname($plugin_config);
|
||||||
$loading_queue[$plugin_instance->getWeight() . "_" . $offset] = $plugin_instance;
|
if ($plugin_instance->initialized) {
|
||||||
$offset++;
|
$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
|
// Sort queue in order to plugins' weights
|
||||||
uksort($loading_queue, 'strnatcmp');
|
uksort($loading_queue, 'strnatcmp');
|
||||||
|
Loading…
Reference in New Issue
Block a user