Created
November 4, 2014 16:27
-
-
Save atuttle/70120908291ec7a74980 to your computer and use it in GitHub Desktop.
How I like to do configuration with DI/1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
function getEnvironment(){ | |
if (cgi.server_name contains ".local" or cgi.server_name contains ".dev"){ | |
return "dev"; | |
} | |
if (cgi.server_name contains "qa."){ | |
return "qa"; | |
} | |
return "prod"; | |
} | |
function setupApplication(){ | |
var bf = new framework.ioc('/com/fusiongrokker/public'); | |
setBeanFactory(bf); | |
//tell the config service which environment it's running in | |
bf.getBean('configService').setEnvironment( getEnvironment() ); | |
bf.getBean('bugLogService')._init( | |
bugLogListener = getSetting('buglog_url') | |
,bugEmailRecipients = getSetting('buglog_emails') | |
,bugEmailSender = getSetting('buglog_sender') | |
,apikey = getSetting('buglog_apikey') | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
variables.currentEnvironment = "prod"; | |
variables.environments = { | |
prod = { | |
env = "prod" | |
,stripe_public = '...' | |
,stripe_private = '...' | |
,buglog_url = '...' | |
,buglog_emails = '...' | |
,buglog_sender = '...' | |
,buglog_apikey = '...' | |
,website_from_email = "..." | |
} | |
,qa = { | |
env = "qa" | |
,stripe_public = '...' | |
,stripe_private = '...' | |
,buglog_url = '...' | |
,buglog_emails = '...' | |
,buglog_sender = '...' | |
,buglog_apikey = '...' | |
,website_from_email = "..." | |
} | |
,dev = { | |
env = "dev" | |
,stripe_public = '...' | |
,stripe_private = '...' | |
,buglog_url = '...' | |
,buglog_emails = '...' | |
,buglog_sender = '...' | |
,buglog_apikey = '...' | |
,website_from_email = "..." | |
} | |
}; | |
function setEnvironment(env){ | |
variables.currentEnvironment = env; | |
} | |
function getSetting(key){ | |
var settings = variables.environments[variables.currentEnvironment]; | |
if (structKeyExists(settings,arguments.key)){ | |
return settings[arguments.key]; | |
}else{ | |
throw(message="Setting not found: `" & arguments.key & "`"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment