Well I know I just released the SimpleConfig.cfc but, I didn’t think it was as flexible as some might need. The new version uses one config file and can load any datatype that ColdFusion will understand in WDDX format, so if you already have configuration variables in your App Scope you can just write them out as a WDDX file and copy the values into “config.wddx” under the “Base” node and then just add your instances under the INSTANCES node in “config.wddx”

Click to download source files

I think this is pretty self explanatory when you take a peek at the code, I even simplified the required application.cfc code to be as easy as possible:

Application.cfc:


<cffunction name="OnApplicationStart">
        <cflock type="exclusive" scope="Application" timeout="60">
            <cfset WDDXConfig = createObject("component","org.ross.WDDXConfig") />
            <!--- optional parameters to WDDXConfig are as follows:
                 WDDXConfig.init("/config/", "config.wddx", "config")
                "/config/" is the mapping where your config files are
                "config.wddx" is your configuration file name
                "config" is the name of your Application variable where your configuration options are going
                 --->
            <cfset WDDXConfig.init() />

        </cflock>
    </cffunction>

config.wddx

This file is pretty simple, if you need some help understanding what it will translate to when you run the app, just run it and see the dump of “Application”


<?xml version="1.0"?>
<wddxPacket version="1.0">
    <header/>
    <data>
        <struct>
            <var name="INSTANCES">
                <!-- don't for get to iterate the length below as you add instances -->
                <array length="1">
                    <struct>
                        <var name="instanceType"><string>QA</string></var>
                        <!-- because you could be running multiple instances on the same machine
                         and thus the physical name could be the same (and we can't rely on CGI variables to be clean)
                         we use an identifying directory name here and the identifier will be placed
                         into the app scope as "ACTUALPATH" incase you are unsure of the physical path to your Application.cfc
                         C:\mysites\steve\appname\Application.cfc or mac: /mysites/steve/appname/Application.cfc -->
                        <var name="identifier"><string>/Volumes/Case Sensitive/www/simpleconfig/html/</string></var>
                        <var name="OVER_RIDE">
                            <struct>
                                <!-- override your base settings here -->
                                <var name="DSNs">
                                    <struct>
                                        <var name="marketing"><string>marketingDSNLocal</string></var>
                                    </struct>
                                </var>
                            </struct>
                        </var>
                    </struct>
                </array>
            </var>
            <!-- all of your base configuration data will go here -->
            <var name="BASE">
                <struct>
                    <var name="instanceType"><string>Development</string></var>
                    <var name="DSNs">
                        <struct>
                            <var name="marketing"><string>marketingPROD</string></var>
                        </struct>
                    </var>
                    <var name="additionalConfigFiles">
                        <array length="1">
                            <!-- as an example I'm just reloading the config.wddx file into another struct,
                             you can do as many additional wddx based config files as you want
                              (structName is the substruct name and fileName is the file name)-->
                            <struct>
                                <var name="structName"><string>sample</string></var>
                                <var name="fileName"><string>config.wddx</string></var>
                            </struct>
                        </array>
                    </var>
                </struct>
            </var>
        </struct>
    </data>
</wddxPacket>


2 Responses to “WDDXConfig - replaces SimpleConfig.cfc now with more simple!”

  1. Sebastiaan Says:

    Hi Steven,

    it seems we indepentently of eachother have developed the same tool (we just haven’t released our source). We use a single config file for all settings and one per environment, as well as a config file for all translations of static parts of our new (well, new, it was released in the Fall of 2008) website http://home.szw.nl/. The Fusebox 5.5 app then can handle all languages it is fed. Coldfusion is wonderful ;-)

  2. wentintuilm Says:

    FANTASTIC!

Sorry, comments are closed for this article.