
The plugin support at the moment is quite simple, I would like to suggest something a bit more complicated, that I believe wouldn't add any charge to the server but would allow ML to be much more versatile.
The limitation with the current systeme that is being used in all the controlers is; it doesen't allow us to replace an existing plugin without changing the rest of the plugins.For example if you remove the localrecords plugin of XAseco to replace it with a superLocalRecords plugin all the widget plugins will suffer, and will need to be updated.
I am proposing a way to minimize such impacts.
The current method in a small SR image would be somehing like this :

What I propose is something like this

here plugin3 has replaced plugin2. If the develloper of plugin1 asks for plugin2 he will get the object of plugin3. Ofcourse the dev of plugin3 will need to make attention to have the same public methods and return the same data. YOu could just add an abstract class called well plugin2abs and make plugin2 and plugin3 extend that one. Then plugin1 is coded taking in considaration the plugin1abs.
There is quite a few examples where such a method with help us. For example a window manager? ML comes with a Default WM, and then we devs can upgrade by simply extending the default one without touching the orginal ML code. Users will add our WM and will not need to modify anything. THey will just need to load our plugin.
I have been working on a FrameWork that uses this method, so here is how I do it
Code: Select all
namespace OWeb\manage;
/**
* Will manages the Extensions of OWeb.
*
* The Extension managers is family dependent.
* Meaning that if a plugin extends another one it can't be used at the same time as the other one.
* This allows you to replace a plugin without changing the code that used the all version. As the
* Extension manager
*
* @author De Cramer Oliver
*/
class Extensions extends \OWeb\utils\Singleton{
private $extensions = array();
private $obj_extension = array();
private $notInit = true;
function __construct() {
\OWeb\manage\Events::getInstance()->registerEvent('Init@OWeb', $this, 'init_extensions');
}
public function tryGetExtension($ext){
try{
return $this->getExtension($ext);
}catch(\Exception $e){
return null;
}
}
/**
* If the extensions is loaded will just return it,
* if not will try to load it and the return it
*
* @param type $ext The name of the extension you want to get
* @return The extension you asked for
* @throws \OWeb\manage\exceptions\Extension If the extension isn't already loaded and can't be loaded.
*/
public function getExtension($ext) {
$name = "Extension\\".$ext;
if (isset($this->extensions[$name])) {
return $this->extensions[$name];
}
else if($this->notInit){
try{
$extension = $this->loadExtension($name);
}catch(\Exception $exception){
throw new \OWeb\manage\exceptions\Extension("YOu can't get this extension. It hasn't been already loaded and can't be loaded now",0,$exception);
}
return $extension;
}else{
throw new \OWeb\manage\exceptions\Extension("You cant load a extension after initialisation completed");
}
}
/**
* Will load the extension if it hasn't already been load and if it can find it.
*
* @param type $ClassName The name of the extension to be loaded.
* @return \OWeb\type\Extension The extension that has been loaded
* @throws \OWeb\manage\exceptions\Extension
*/
protected function loadExtension($ClassName){
try{
$extension = new $ClassName();
if($extension instanceof \OWeb\types\Extension){
$this->registerExtension($extension, $ClassName);
return $extension;
}else
throw new \OWeb\manage\exceptions\Extension("The Extension isn't an instance of : \OWeb\\types\Extension");
}catch(\Exception $ex){
throw new \OWeb\manage\exceptions\Extension("The extension couldn't be loaded.", 0, $ex);
}
}
/**
* Register the extension to the Extension manager.
* It is here that we will check all the parents of the extension to Register for every parents it has.
*
* @param type $extension The Extension Object
* @param type $name THe name of the Extension
* @throws \OWeb\Exception If the extension has been already loaded.
*/
protected function registerExtension($extension, $name){
$subExtensions = array();
$subExtensions[$name] = $extension;
$parent = get_parent_class($extension);
/*foreach($this->extensions as $name => $ext){
echo ".".$name."------------------";
}*/
while($parent != "" && $parent != "OWeb\\types\\Extension" ){
if(isset($this->extensions[$parent])){
throw new \OWeb\Exception("The plugin '$name' has already been registered as : ".get_class($this->extensions[$parent]));
}
$subExtensions[$parent] = $extension;
$parent = get_parent_class($parent);
}
$this->obj_extension[$name] = $extension;
$this->extensions = array_merge($this->extensions, $subExtensions);
}
/**
* Will initialize all extensions when Oweb has finished Initializing itself
*/
public function init_extensions(){
foreach ($this->obj_extension as $extension) {
$extension->OWeb_Init();
}
$this->notInit = false;
\OWeb\manage\Events::getInstance()->sendEvent('Init@OWeb\manage\Etensions');
}
}