Procházet zdrojové kódy

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.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2708 a333f486-631f-4898-b8df-5754b55c2be0
dflaven před 12 roky
rodič
revize
5a7fd8cbf1
1 změnil soubory, kde provedl 36 přidání a 1 odebrání
  1. 36 1
      setup/modulediscovery.class.inc.php

+ 36 - 1
setup/modulediscovery.class.inc.php

@@ -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)