Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add a new dependency type phpExtension to avoid loading plugin that h…
Browse files Browse the repository at this point in the history
…ave a strong dependency to one or more php extensions.
  • Loading branch information
cdujeu committed Apr 17, 2015
1 parent 19d91eb commit ba53d8a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
26 changes: 25 additions & 1 deletion core/src/core/classes/class.AJXP_Plugin.php
Expand Up @@ -55,6 +55,7 @@ class AJXP_Plugin implements Serializable
protected $pluginConf; // can be passed at load time
protected $pluginConfDefinition;
protected $dependencies;
protected $extensionsDependencies;
protected $streamData;
protected $mixins = array();
public $loadingState = "";
Expand Down Expand Up @@ -85,7 +86,7 @@ class AJXP_Plugin implements Serializable
"contributionsLoaded",
"mixins",
"streamData",
"options", "pluginConf", "pluginConfDefinition", "dependencies", "loadingState", "manifestXML");
"options", "pluginConf", "pluginConfDefinition", "dependencies", "extensionsDependencies", "loadingState", "manifestXML");

/**
* Construction method
Expand All @@ -102,6 +103,7 @@ public function __construct($id, $baseDir)
$this->name = $split[1];
$this->actions = array();
$this->dependencies = array();
$this->extensionsDependencies = array();
}

protected function getPluginWorkDir($check = false)
Expand Down Expand Up @@ -487,6 +489,11 @@ protected function loadDependencies()
$value = $attr->value;
$this->dependencies = array_merge($this->dependencies, explode("|", $value));
}
$extPaths = "dependencies/phpExtension/@name";
$nodes = $this->xPath->query($extPaths);
foreach ($nodes as $attr) {
$this->extensionsDependencies[] = $attr->value;
}
}
/**
* Update dependencies dynamically
Expand Down Expand Up @@ -644,6 +651,23 @@ public function getClassFile()
if(!$files->length) return false;
return $this->nodeAttrToHash($files->item(0));
}

public function missingExtensions(){
$missing = array();
if(count($this->extensionsDependencies)){
foreach($this->extensionsDependencies as $ext){
if (!extension_loaded($ext)) {
$missing[] = $ext;
}
}
}
return $missing;
}

public function hasMissingExtensions(){
return count($this->missingExtensions()) > 0;
}

/**
* @return bool
*/
Expand Down
6 changes: 5 additions & 1 deletion core/src/core/classes/class.AJXP_PluginsService.php
Expand Up @@ -253,6 +253,10 @@ private function checkDependencies(&$arrayToSort)
// First make sure that the given dependencies are present
foreach ($arrayToSort as $plugId => $plugObject) {
$plugObject->updateDependencies($this);
if($plugObject->hasMissingExtensions()){
unset($arrayToSort[$plugId]);
continue;
}
$dependencies = $plugObject->getDependencies();
if(!count($dependencies)) continue;// return ;
$found = false;
Expand Down Expand Up @@ -399,7 +403,7 @@ public function initActivePlugins()
$pObject->init(array());
try {
$pObject->performChecks();
if(!$pObject->isEnabled()) continue;
if(!$pObject->isEnabled() || $pObject->hasMissingExtensions()) continue;
$this->setPluginActiveInst($pObject->getType(), $pObject->getName(), true);
} catch (Exception $e) {
//$this->errors[$pName] = "[$pName] ".$e->getMessage();
Expand Down
6 changes: 6 additions & 0 deletions core/src/plugins/core.ajaxplorer/ajxp_registry.xsd
Expand Up @@ -765,6 +765,7 @@
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="activePlugin"/>
<xs:element ref="phpExtension"/>
<xs:element ref="pluginClass"/>
<xs:element name="pluginResources">
<xs:complexType>
Expand All @@ -779,6 +780,11 @@
<xs:attribute name="pluginName" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="phpExtension">
<xs:complexType>
<xs:attribute name="name" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="pluginClass">
<xs:complexType>
<xs:attribute name="pluginName" use="required"/>
Expand Down

0 comments on commit ba53d8a

Please sign in to comment.