inheritance configuration |
Ketan Jetty
enthusiasm for technology
|
||||||||||||||||||||||
![]() ![]() |
|||||||||||||||||||||||
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.
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> |
|
||||||||||||||||||||||
Ketan Jetty @ 2010. All Rights Reserved. |