Skip to content

Instantly share code, notes, and snippets.

@bpanulla
Created June 16, 2011 23:32
Show Gist options
  • Save bpanulla/1030562 to your computer and use it in GitHub Desktop.
Save bpanulla/1030562 to your computer and use it in GitHub Desktop.
Composing an Application.cfc via function copying
<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>
<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