In older projects with fusebox.xml
we're using another copy of the config called server.xml
.
This file is typically out of source control, so it allows easy configuration of application instances. It's structure is pretty the same as fusebox.xml
, but includes only attributes which we want to override for current instance, for example datasource or paths:
<?xml version="1.0" encoding="UTF-8"?>
<server>
<parameter name="mode" value="development-full-load" />
<parameter name="datasource" value="my_datasource" />
<parameter name="logRotatePeriod" value="50" />
<parameter name="someDataPath" value="/home/xxx/yyy/zzz/"/>
</server>
In the fusebox.appinit.cfm
or fusebox.init.cfm
(depending how frequently this file is changed, or any other reasons) this file is parsed and matching entries in application.fusebox
are updated. For example, here's the function for doing this:
<cffunction name="loadLocalConfig" returntype="void" output="false" hint="Read and apply local server.xml configuration">
<cfscript>
var filesServerPath = application.fusebox.AppRootDirectory & application.fusebox.filesServer;
var fileParameters = "";
var oFileParameters = "";
var aServer = "";
var i = "";
if (FileExists(filesServerPath)) {
// read the contents
fileParameters = FileRead(filesServerPath);
// parse XML text into object
oFileParameters = XMLParse(trim(fileParameters));
// get fusebox parameters and update their values
if (StructKeyExists(oFileParameters, "server")){
aServer = oFileParameters.server.XmlChildren;
for (i=1; i LTE ArrayLen(aServer); i=i+1) {
if (aServer[i].XmlName EQ "parameter" AND StructKeyExists(application.fusebox, aServer[i].XmlAttributes.name)) {
application.fusebox[aServer[i].XmlAttributes.name] = aServer[i].XmlAttributes.value;
}
}
}
}
</cfscript>
</cffunction>
BTW, for safety we usually rename them to the fusebox.xml.cfm
/server.xml.cfm
-- it does not make it CFML file, but protects from direct access without web-server tricks
Also it worth mentioning that in latest (since 2009) Fusebox-based projects we've used Application.cfc
for configuration. These are modern-style applications with much better control over the initialization and other stuff available as Application.cfc
methods.
With this approach Fusebox is configured as FUSEBOX_PARAMETERS
scope. It's even easier to override its values, simply include server.cfm
file and put there a chunk of plain CFScript with FUSEBOX_PARAMETERS.datasource = "my_datasource"
.