Created
June 16, 2011 23:32
-
-
Save bpanulla/1030562 to your computer and use it in GitHub Desktop.
Composing an Application.cfc via function copying
This file contains 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
<cfcomponent output="false"> | |
<cfscript> | |
function init() | |
{ | |
// Application settings | |
this.name = "OMNOMno.us"; | |
this.applicationTimeout = createTimespan(5,0,0,0); | |
this.loginStorage = "session"; | |
this.clientManagement = false; | |
this.sessionManagement = true; | |
this.sessionTimeout = createTimespan(0,1,0,0); | |
// Application environment | |
this.webRoot = GetDirectoryFromPath(GetCurrentTemplatePath()); | |
this.apiRoot = this.webRoot & "api"; | |
this.projectRoot = createObject("java", "java.io.File") | |
.init(this.webRoot) | |
.getParent(); | |
this.mappings = {}; | |
this.mappings["/"] = this.projectRoot & "/src"; | |
} | |
function onApplicationStart() | |
{ | |
var local = structNew(); | |
// Set up ColdSpring Object Factory | |
local.beanFactory = CreateObject('component', 'coldspring.beans.DefaultXmlBeanFactory') | |
.init(defaultProperties=this.properties); | |
local.beanFactory.loadBeans(this.properties.resourceFolder & "/coldspring.xml"); | |
// Copy references to properties and bean factory to Application scope | |
application.properties = this.properties; | |
application.beanFactory = local.beanFactory; | |
// Save timestamp of application initialization | |
application.init = Now(); | |
return true; | |
} | |
function onRequestStart( request ) | |
{ | |
if ( isDefined("URL.debug") ) | |
{ | |
application.properties.debug = URL.debug EQ true; | |
} | |
if ( isDefined("URL.appReset") ) | |
{ | |
onApplicationStart(); | |
redirect(application.properties.rootUri); | |
} | |
// Check debugging setting | |
applySettings( showdebugoutput:application.properties.debug ); | |
return true; | |
} | |
</cfscript> | |
</cfcomponent> |
This file contains 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
<cfcomponent output="false"> | |
<cfinclude template="functions.cfm"> | |
<cfscript> | |
// Get a handle on the Configuration component | |
this.config = createObject("component", "AppConfig"); | |
// Wire up methods | |
init = this.config.init; | |
onApplicationStart = this.config.onApplicationStart; | |
onRequestStart = this.config.onRequestStart; | |
// Initialize application | |
init(); | |
</cfscript> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment