<!--- 
mach-ii.cfm
author: Ben Edwards (document header by Leon Chalnick)
This configures and loads the mach-ii framework
--->

<!--- Set the path to the application's mach-ii.xml file. --->
<cfset MACHII_CONFIG_PATH = ExpandPath("./config/mach-ii.xml") />
<!--- Set the configuration mode (when to reload): -1=never, 0=dynamic, 1=always --->
<cfset MACHII_CONFIG_MODE = 1 />
<!--- Set the app key for sub-applications within a single cf-application. --->
<cfset MACHII_APP_KEY = GetFileFromPath(ExpandPath(".")) />

<cfif NOT StructKeyExists(application,MACHII_APP_KEY)>
  <cfset application[MACHII_APP_KEY] = StructNew() />
</cfif>

<!--- Create the AppLoader if necessary. --->
<!---<cfset application[MACHII_APP_KEY].appLoader = "" /> --->
<cfif NOT (StructKeyExists(application[MACHII_APP_KEY],'appLoader') AND
    IsObject(application[MACHII_APP_KEY].appLoader))>
  <cfset application[MACHII_APP_KEY].appLoader = CreateObject('component', 'MachII.framework.AppLoader') />
  <cfset application[MACHII_APP_KEY].appLoader.init(MACHII_CONFIG_PATH) />
</cfif>

<!--- Reload the configuration if necessary. --->
<cfif MACHII_CONFIG_MODE EQ 1>
  <cfset application[MACHII_APP_KEY].appLoader.reloadConfig() />
<cfelseif MACHII_CONFIG_MODE EQ 0 AND application[MACHII_APP_KEY].appLoader.shouldReloadConfig()>
  <cfset application[MACHII_APP_KEY].appLoader.reloadConfig() />
<cfelseif MACHII_CONFIG_MODE EQ -1>
  <!--- Do not reload config. --->
</cfif>

<!--- Handle the Request. --->
<cfset application[MACHII_APP_KEY].appLoader.getAppManager().getRequestHandler().handleRequest() />


