Ask Ben: Environment-Based Application.cfc Settings

<cfcomponent
	output="false"
	hint="Executes application-level event handlers.">
 
	<!--- Set up the application. --->
	<cfset THIS.Name = Config().Name />
	<cfset THIS.ApplicationTimeout = Config().ApplicationTimeout />
	<cfset THIS.SessionTimeout = Config().SessionTimeout />
 
	<!--- Set up page settings. --->
	<cfsetting
		showdebugoutput="#Config().ShowDebugOutput#"
		requesttimeout="#Config().RequestTimeout#"
		/>
 
 
	<cffunction
		name="Config"
		access="public"
		returntype="struct"
		output="false"
		hint="Returns the Application.cfc configuration settings struct based on the execution environment (production, staging, development, etc).">
 
		<!---
			Check to see if the app config structure
			exists within this ColdFusion component yet;
			if it doesn't we have to created it.
		--->
		<cfif NOT StructKeyExists( THIS, "$Config" )>
 
			<!---
				Create the empty $AppCongif struct. I am
				starting it off with "$" to minimize the
				chances of it conflicting with an existing
				variable (or soon to be existing variabel).
			--->
			<cfset THIS[ "$Config" ] = StructNew() />
 
			<!---
				The applicaiton configuration object does
				not yet exist. Let's create it based on the
				server name.
			--->
			<cfif REFind( "(?i)swoop", CGI.server_name )>
 
				<!--- Set development environment. --->
				<cfset THIS[ "$Config" ].IsLive = false />
				<cfset THIS[ "$Config" ].Name = "BenNadel-DEV" />
				<cfset THIS[ "$Config" ].ApplicationTimeout =
						CreateTimeSpan( 0, 0, 1, 0 ) />
				<cfset THIS[ "$Config" ].SessionTimeout =
						CreateTimeSpan( 0, 0, 1, 0 ) />
 
				<!--- Page settings. --->
				<cfset THIS[ "$Config" ].ShowDebugOutput = true />
				<cfset THIS[ "$Config" ].RequestTimeout = 20 />
 
			<cfelse>
 
				<!--- Set production environment. --->
				<cfset THIS[ "$Config" ].IsLive = true />
				<cfset THIS[ "$Config" ].Name = "BenNadel-PROD" />
				<cfset THIS[ "$Config" ].ApplicationTimeout =
						CreateTimeSpan( 0, 0, 10, 0 ) />
				<cfset THIS[ "$Config" ].SessionTimeout =
						CreateTimeSpan( 0, 0, 10, 0 ) />
 
				<!--- Page settings. --->
				<cfset THIS[ "$Config" ].ShowDebugOutput = false />
				<cfset THIS[ "$Config" ].RequestTimeout = 20 />
 
			</cfif>
 
		</cfif>
 
 
		<!---
			ASSERT: Whether we are calling this function
			for the first time of the Nth time, we now
			have the $Config object properly stored
			in the THIS scope of the Application.cfc
		--->
 
 
		<!--- Return the config object. --->
		<cfreturn THIS[ "$Config" ] />
	</cffunction>
 
</cfcomponent>

For Cut-and-Paste