Enhancement: the expression of dependencies between modules can now use a complex boolean expression with a combination of "logical or" (||) and "logical and" (&&) instead of just a module name.

SVN:trunk[2708]
This commit is contained in:
Denis Flaven
2013-04-29 08:39:23 +00:00
parent 6df6af0df0
commit 29060f7b5e

View File

@@ -124,7 +124,7 @@ class ModuleDiscovery
$bDependenciesSolved = true;
foreach($aRemainingDeps as $sDepId)
{
if (!in_array($sDepId, $aOrderedModules))
if (!self::DependencyIsResolved($sDepId, $aOrderedModules))
{
$bDependenciesSolved = false;
}
@@ -167,6 +167,41 @@ class ModuleDiscovery
}
return $aResult;
}
protected static function DependencyIsResolved($sDepString, $aOrderedModules)
{
$bResult = false;
if (preg_match_all('/([^\(\)&| ]+)/', $sDepString, $aMatches))
{
$aReplacements = array();
foreach($aMatches as $aMatch)
{
foreach($aMatch as $sModuleId)
{
if (in_array($sModuleId, $aOrderedModules))
{
// module is present
$aReplacements[$sModuleId] = '(true)'; // Add parentheses to protect against invalid condition causing
// a function call that results in a runtime fatal error
}
else
{
// module is not present
$aReplacements[$sModuleId] = '(false)'; // Add parentheses to protect against invalid condition causing
// a function call that results in a runtime fatal error
}
}
}
$sBooleanExpr = str_replace(array_keys($aReplacements), array_values($aReplacements), $sDepString);
$bOk = @eval('$bResult = '.$sBooleanExpr.'; return true;');
if($bOk == false)
{
SetupPage::log_warning("Eval of $sRelDir/$sFile returned false");
echo "Failed to parse the boolean Expression = '$sBooleanExpr'<br/>";
}
}
return $bResult;
}
/**
* Search (on the disk) for all defined iTop modules, load them and returns the list (as an array)