I wrote a simple "flattener" that will take nested structs and
collapse them so ColdSpring can dereference them. So if you have this
struct:
config = {
dsn = {
one = "onedsn",
two = "twodsn"
}
};
it'll convert it into this:
config = {
dsn = {
one = "onedsn",
two = "twodsn"
},
"dsn.one" = "onedsn",
"dsn.two" = "twodsn"
};
Here's the code:
<cffunction name="prepForColdSpring" access="public" output="false"
returntype="struct"
hint="I collapse all nested structs into dot-delimited top-level keys">
<cfargument name="config" type="struct" required="true" />
<cfset prepForColdSpringInternal(config, "", config) />
<cfreturn config />
</cffunction>
<cffunction name="prepForColdSpringInternal" access="private"
output="false" returntype="void">
<cfargument name="root" type="struct" required="true" />
<cfargument name="path" type="string" required="true" />
<cfargument name="config" type="struct" required="true" />
<cfset var i = "" />
<cfloop collection="#config#" item="i">
<cfif isStruct(config[i])>
<cfset prepForColdSpringInternal(root, listAppend(path, i, "."),
config[i]) />
<cfelseif path NEQ "">
<cfset root[listAppend(path, i, ".")] = config[i] />
</cfif>
</cfloop>
</cffunction>
cheers,
barneyb
--
Barney Boisvert
bboi...@gmail.com
http://www.barneyb.com/