瀏覽代碼

- new Configuration option 'source_dir'
- pretty print of the configuration

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2233 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 12 年之前
父節點
當前提交
4eda5a1a72
共有 1 個文件被更改,包括 99 次插入32 次删除
  1. 99 32
      core/config.class.inc.php

+ 99 - 32
core/config.class.inc.php

@@ -528,6 +528,15 @@ class Config
 			'source_of_value' => '',
 			'show_in_conf_sample' => false,
 		),
+		'source_dir' => array(
+			'type' => 'string',
+			'description' => 'Source directory for the datamodel files. (which gets compiled to env-production).',
+			// examples... not used
+			'default' => 'datamodels/latest',
+			'value' => '',
+			'source_of_value' => '',
+			'show_in_conf_sample' => true,
+		),
 	);
 
 	public function IsProperty($sPropCode)
@@ -1245,64 +1254,98 @@ class Config
 			fwrite($hFile, "<?php\n");
 			fwrite($hFile, "\n/**\n");
 			fwrite($hFile, " *\n");
-			fwrite($hFile, " * phpMyORM configuration file, generated by the iTop configuration wizard\n");
+			fwrite($hFile, " * Configuration file, generated by the ".ITOP_APPLICATION." configuration wizard\n");
 			fwrite($hFile, " *\n");
 			fwrite($hFile, " * The file is used in MetaModel::LoadConfig() which does all the necessary initialization job\n");
 			fwrite($hFile, " *\n");
 			fwrite($hFile, " */\n");
-			fwrite($hFile, "\n");
 			
+			$aConfigSettings = $this->m_aSettings;
+			
+			// Old fashioned boolean settings
+			$aBoolValues = array(
+				'log_global' => $this->m_bLogGlobal,
+				'log_notification' => $this->m_bLogNotification,
+				'log_issue' => $this->m_bLogIssue,
+				'log_web_service' => $this->m_bLogWebService,
+				'secure_connection_required' => $this->m_bSecureConnectionRequired,
+			);
+			foreach($aBoolValues as $sKey => $bValue)
+			{
+				$aConfigSettings[$sKey] = array(
+					'show_in_conf_sample' => true,
+					'type' => 'bool',
+					'value' => $bValue,
+				);
+			}
+			
+			// Old fashioned non boolean values
+			$aOtherValues = array(
+				'db_host' => $this->m_sDBHost,
+				'db_user' => $this->m_sDBUser,
+				'db_pwd' => $this->m_sDBPwd,
+				'db_name' => $this->m_sDBName,
+				'db_subname' => $this->m_sDBSubname,
+				'db_character_set' => $this->m_sDBCharacterSet,
+				'db_collation' => $this->m_sDBCollation,
+				'default_language' => $this->m_sDefaultLanguage,
+				'allowed_login_types' => $this->m_sAllowedLoginTypes,
+				'encryption_key' => $this->m_sEncryptionKey,
+				'csv_import_charsets' => $this->m_aCharsets,
+			);
+			foreach($aOtherValues as $sKey => $value)
+			{
+				$aConfigSettings[$sKey] = array(
+					'show_in_conf_sample' => true,
+					'type' => is_string($value) ? 'string' : 'mixed',
+					'value' => $value,
+				);
+			}
+			
+			ksort($aConfigSettings);
 			fwrite($hFile, "\$MySettings = array(\n");
-			foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
+			foreach($aConfigSettings as $sPropCode => $aSettingInfo)
 			{
 				if ($aSettingInfo['show_in_conf_sample'])
 				{
-					$sType = $this->m_aSettings[$sPropCode]['type'];
+					$sType = $aSettingInfo['type'];
 					switch($sType)
 					{
 					case 'bool':
-						$sSeenAs = $aSettingInfo['value'] ? '1' : '0';
+						$sSeenAs = $aSettingInfo['value'] ? 'true' : 'false';
 						break;
 					default:
-						$sSeenAs = "'".addslashes($aSettingInfo['value'])."'";
+						$sSeenAs = self::PrettyVarExport($aSettingInfo['value'], "\t");
+					}
+					fwrite($hFile, "\n");
+					if (isset($aSettingInfo['description']))
+					{
+						fwrite($hFile, "\t// $sPropCode: {$aSettingInfo['description']}\n");
+					}
+					if (isset($aSettingInfo['default']))
+					{
+						$default = $aSettingInfo['default'];
+						if ($aSettingInfo['type'] == 'bool')
+						{
+							$default = $default ? 'true' : 'false';
+						}
+						fwrite($hFile, "\t//\tdefault: ".self::PrettyVarExport($aSettingInfo['default'],"\t//\t\t", true)."\n");
 					}
 					fwrite($hFile, "\t'$sPropCode' => $sSeenAs,\n");
 				}
 			}
-			fwrite($hFile, "\t'db_host' => '{$this->m_sDBHost}',\n");
-			fwrite($hFile, "\t'db_user' => '{$this->m_sDBUser}',\n");
-			fwrite($hFile, "\t'db_pwd' => '".addslashes($this->m_sDBPwd)."',\n");
-			fwrite($hFile, "\t'db_name' => '{$this->m_sDBName}',\n");
-			fwrite($hFile, "\t'db_subname' => '{$this->m_sDBSubname}',\n");
-			fwrite($hFile, "\t'db_character_set' => '{$this->m_sDBCharacterSet}',\n");
-			fwrite($hFile, "\t'db_collation' => '{$this->m_sDBCollation}',\n");
-			fwrite($hFile, "\n");
-			fwrite($hFile, "\t'log_global' => {$this->m_bLogGlobal},\n");
-			fwrite($hFile, "\t'log_notification' => {$this->m_bLogNotification},\n");
-			fwrite($hFile, "\t'log_issue' => {$this->m_bLogIssue},\n");
-			fwrite($hFile, "\t'log_web_service' => {$this->m_bLogWebService},\n");
-			fwrite($hFile, "\t'min_display_limit' => {$this->m_iMinDisplayLimit},\n");
-			fwrite($hFile, "\t'max_display_limit' => {$this->m_iMaxDisplayLimit},\n");
-			fwrite($hFile, "\t'standard_reload_interval' => {$this->m_iStandardReloadInterval},\n");
-			fwrite($hFile, "\t'fast_reload_interval' => {$this->m_iFastReloadInterval},\n");
-			fwrite($hFile, "\t'secure_connection_required' => ".($this->m_bSecureConnectionRequired ? 'true' : 'false').",\n");
-			fwrite($hFile, "\t'default_language' => '{$this->m_sDefaultLanguage}',\n");
-			fwrite($hFile, "\t'allowed_login_types' => '{$this->m_sAllowedLoginTypes}',\n");
-			fwrite($hFile, "\t'encryption_key' => '{$this->m_sEncryptionKey}',\n");
-			$sExport = var_export($this->m_aCharsets, true);
-			fwrite($hFile, "\t'csv_import_charsets' => $sExport,\n");
-
 			fwrite($hFile, ");\n");
-
+			
 			fwrite($hFile, "\n");
+			fwrite($hFile, "/**\n *\n * Modules specific settings\n *\n */\n");
 			fwrite($hFile, "\$MyModuleSettings = array(\n");
 			foreach ($this->m_aModuleSettings as $sModule => $aProperties)
 			{
 				fwrite($hFile, "\t'$sModule' => array (\n");
 				foreach ($aProperties as $sProperty => $value)
 				{
-					$sExport = var_export($value, true);
-					fwrite($hFile, "\t\t'$sProperty' => $sExport,\n");
+					$sNiceExport = self::PrettyVarExport($value, "\t\t");
+					fwrite($hFile, "\t\t'$sProperty' => $sNiceExport,\n");
 				}
 				fwrite($hFile, "\t),\n");
 			}
@@ -1501,6 +1544,30 @@ class Config
 		self::ChangePrefix($this->m_aWebServiceCategories, $sSearchPrefix, $sNewPrefix);
 		self::ChangePrefix($this->m_aDictionaries, $sSearchPrefix, $sNewPrefix);
 	}
+	
+	/**
+	 * Pretty format a var_export'ed value so that (if possible) the identation is preserved on every line
+	 * @param mixed $value The value to export
+	 * @param string $sIdentation The string to use to indent the text
+	 * @param bool $bForceIndentation Forces the identation (enven if it breaks/changes an eval, for example to ouput a value inside a comment)
+	 * @return string The indented export string
+	 */
+	protected static function PrettyVarExport($value, $sIdentation, $bForceIndentation = false)
+	{
+		$sExport = var_export($value, true);
+		$sNiceExport = trim(preg_replace("/^/m", "\t\t\t", $sExport));
+		if (!$bForceIndentation)
+		{
+			eval('$aImported='.$sNiceExport.';');
+			// Check if adding the identations at the beginning of each line
+			// did not modify the values (in case of a string containing a line break)
+			if($aImported != $value)
+			{
+				$sNiceExport = $sExport;
+			}
+		}
+		return $sNiceExport;	
+	}
 
 }
 ?>