Inheritance Configuration

Inheritance configuration or hierarchy configuration is a configuration file that follows the object oriented concept of inheritance to create a compact and managable configuration file. This is developed to steamline the configuration process within CFTurbine.

Most configuration files are basically text or xml files which can be compromised in an unsecured environment. Also most of the config data is duplicated per environment leading to a messy and bulky configuration files.

Inheritance configuration is a coldfusin cfc with one public method getConfig(), which makes it security safe as this method can only be accessed by the server and a hierarchy JSON configuration string which makes the configuration file compact.

The config data is in JSON, which is easily readable and has 2 distinct areas 'current_env' and 'env'.
current_env:  this part sets the server environment "dev","qa","uat","prod"
env:  this section is for setting the configuration parameters.
   base: this is akin to OOP base/parent class. You can set up config params for all environments here. You must place all environment common params here. eg. dsn
   child: dev/qa/uat/prod/[custom env(s)] are the inherited or child sections, the parent being the 'base' section. The base env is automaticaly available to all child environments.

Override key
You can override the base param by creating a similar key in the child. If you have "dsn"="dsnBase" in the base section, by default all environments have the dsn key available with value "dsnBase", now, if you want to override the value for dev environment create a key "dsn"="dsnDev" in dev section.

Append key
You can append to an existing base key by creating similar key appended with "__" double underscore string. If you have "email"="base@email.com" in the base section, by default all environments have the email key available with value "base@email.com", now, if you want to append the value for dev environment create a key "email__"="dev@email.com" in dev section. The dev email key will now have value "base@email.com,dev@email.com"

The following will be generated when you dump the #application# scope.
when "current_env"="dev"   when "current_env"="qa"
 

How to use inheritance configuration / hierarchy configuration
<cffunction name="onApplicationStart" returnType="boolean" output="true">
	<cfset StructClear(application) />
	<cfset application['env'] = createObject("component","config").getConfig() />	
	<cfreturn true />
</cffunction>

config.cfc :: inheritance configuration / hierarchy configuration
<!--- 
*	'base' is the parent env. and rest are the children of the 'base'
*	'base' env. is duplicated in other env.
*	the 'base' key can be overridden by creating a similar key in the respective env.
	eg. if the key 'dsn' is found in the chil env. the 'base' is overridden
	and the child value is used
* 	use '__' suffix appended to key ("admin_mail__") in env. other than 'base' to
	append to base value in the child env
*	Required keys are:
		config.json
			- current_env
		config.json.env.base
			- admin_mail
			- domain
			- dsn
			- file_seperator
			- root
			- show_debug
--->
<cfcomponent>
	<cffunction name="getConfigJSON" access="private" returntype="string">
		<cfset var configJSON = '{
			"current_env":"dev",
			"env":{
				"base":{
					"admin_mail":"admin@ketanJetty.com",
					"domain":"#cgi.SERVER_NAME#",
					"dsn":"dsnKJ",
					"file_seperator":"#Replace(createObject('java', 'java.lang.System').getProperty('file.separator'),'\','\\','ALL')#",
					"root":"#Replace(getDirectoryFromPath(getBaseTemplatePath()),'\','\\','ALL')#",
					"show_debug":false
				},
				"dev":{
					"dsn":"dsnKJdev"
				},
				"qa":{
					"admin_mail__":"qa@ketanJetty.com",
					"dsn":"dsnKJqa",
					"key001":"value001"
				},
				"uat":{
				},
				"prod":{
				}
			}
		}' />
		
		<cfreturn configJSON />
	</cffunction>
	
	<cffunction name="getConfig" access="public" returntype="struct">
		<cfset var config = DeserializeJSON(getConfigJSON()) />
		<cfset var retval = "" />
		
		<cfloop collection="#config.env#" item="i">
			<cfif i NEQ "base">
				<cfif config.current_env  NEQ i>
					<cfset StructDelete(config.env, i) />
				<cfelse>
					<cfloop collection="#config.env.base#" item="j">
						<cfif StructKeyExists(config.env["#i#"], "#j#__")>
							<cfset config.env["#i#"]["#j#"] = listAppend(config.env["#i#"]["#j#__"], #config.env["base"][j]#) />
							<cfset StructDelete(config.env["#i#"], "#j#__")>
						</cfif>
						<cfif NOT StructKeyExists(config.env["#i#"], j)>
							<cfset config.env["#i#"]["#j#"] = #config.env["base"][j]# />
						</cfif>
					</cfloop>	
				</cfif>
			</cfif>
		</cfloop>
		
		<cfset config.env[config.current_env]['env_name'] = config.current_env />
		<cfset StructDelete(config.env, "base") />
		<cfset retval = config.env[config.current_env] />
				
		<cfreturn retval />
	</cffunction>
</cfcomponent>



Ginger CMS
the future of cms, a simple and intuitive content management system ...

ASP.NET MVC Application
best practices like Repository, LINQ, Dapper, Domain objects ...

CFTurbine
cf prototyping engine, generates boilerplate code and views ...

Search Engine LITE
create your own custom search engine for your web site ...

JRun monitor
monitors the memory footprint of JRun engine and auto-restarts a hung engine ...

Validation Library
complete validation library for your web forms ...