Skip to content

Instantly share code, notes, and snippets.

@bcswartz
Created November 23, 2017 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcswartz/226c435623bb2fcc4040bf350320e86b to your computer and use it in GitHub Desktop.
Save bcswartz/226c435623bb2fcc4040bf350320e86b to your computer and use it in GitHub Desktop.
Configure environment-specific settings with ModelGlue and ColdSpring, part 1
<cfcomponent displayname="appConfig" hint="I provide the configuration settings for the application dependent on where the application is running.">
<cffunction name="init" access="public" returntype="any" hint="I accept all of the possible setting configurations">
<cfargument name="universalSettings" type="struct" required="true" hint="A struct of all of the configuration settings that are true regardless of environment" />
<cfargument name="localSettings" type="struct" required="true" hint="A struct of all of the configuration settings for the local environment" />
<cfargument name="remoteSettings" type="struct" required="true" hint="A struct of all of the configuration settings for the remote environment" />
<cfset var loc= StructNew()>
<cfset variables.config= StructNew()>
<cfloop collection="#arguments.universalSettings#" item="loc.ukey">
<cfset variables.config[loc.ukey]= arguments.universalSettings[loc.ukey]>
</cfloop>
<cfset loc.env= determineEnvironment()>
<cfloop collection="#arguments[loc.env]#" item="loc.ekey">
<cfset variables.config[loc.ekey]= arguments[loc.env][loc.ekey]>
</cfloop>
<cfreturn this />
</cffunction>
<cffunction name="determineEnvironment" access="private" output="false" returntype="string" hint="I determine the application environment">
<cfif Left(cgi.cf_template_path,6) EQ "/Users">
<cfreturn "localSettings" />
<cfelse>
<cfreturn "remoteSettings" />
</cfif>
</cffunction>
<cffunction name="getConfig" access="public" output="false" returntype="any" hint="I return a config setting">
<cfargument name="configName" type="string" required="true" hint="The name of the configuration setting">
<cfreturn variables.config[arguments.configName]>
</cffunction>
<cffunction name="setConfig" access="public" output="false" returntype="void" hint="I set a config setting">
<cfargument name="configName" type="string" required="true" hint="The name of the configuration setting">
<cfargument name="configValue" type="any" required="true" hint="The value/data to store in the configuration setting">
<cfset variables.config[arguments.configName]= arguments.configValue>
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment