Adam Cameron
st = {
top = {
middle = {
bottom = "value I want"
}
}
}
And a path to a key held in a string, eg:
keyPath = "top.middle.bottom"
Is the CFML-idiomatic way of fetching the value I want gonna be something like:
valueIWant = structGet("st.#keyPath#")
Repro:
https://trycf.com/gist/ac86ec8b0166c0715e37ac1f74c87684/acf2021?theme=monokai
Note: I know this works, I'm just wondering whetherin CFML-current there's a better way? structGet
always seems so clunky to me. I feel I am forgetting something...bdw429s
09/08/2022, 6:41 PMbdw429s
09/08/2022, 6:41 PMserver set web.ssl.enable=true
translate to a struct behind the scenesbdw429s
09/08/2022, 6:42 PMbdw429s
09/08/2022, 6:43 PMAdam Cameron
evaluate
too. I'm less against it than most, but... it's code I'm using in a blog article and I don't wanna... distract ppl's focus.bdw429s
09/08/2022, 6:46 PMbdw429s
09/08/2022, 6:47 PMAdam Cameron
st[keyPath]
though right, cos that refers to a single key called top.middle.bottom
, it's not resolved, yeah?Adam Cameron
evaluate
in shared code one MUST sanitise it, cos one dun't know what value it's gonna be receiving. Low risk, but... due diligence etc.bdw429s
09/08/2022, 6:49 PMkeyPath.toArray('.')
, then looped over it and did currentPointer[nextKey]
to drill down. But think that's a lot of boilerplatebdw429s
09/08/2022, 6:49 PMAdam Cameron
public any function get(required string key) {
lock scope="application" type="readonly" timeout=5 throwontimeout=true {
if (isDefined("variables.applicationScope.#key#")) {
return structGet("variables.applicationScope.#key#")
}
throw(type="ApplicationScopeProxy.KeyNotFoundException", message="Key [#key#] not found in application scope");
}
}
Adam Cameron
Adam Cameron
isDefined
, but... like evaluate
... it's the tool for the job here I thinkAdam Cameron
structGet
if it worked like structGet(theStruct, thePath)
. I don't like how the struct is in the path too, for some reason.bdw429s
09/08/2022, 6:51 PMAdam Cameron
myStruct.get(path)
would work...Scott Bennett
09/08/2022, 6:51 PMAdam Cameron
Adam Cameron
Scott Bennett
09/08/2022, 6:53 PMAdam Cameron
Scott Bennett
09/08/2022, 6:54 PMbdw429s
09/08/2022, 6:54 PMAdam Cameron
bdw429s
09/08/2022, 6:54 PMAdam Cameron
Evil Ware
09/08/2022, 7:09 PMgavinbaumanis
09/10/2022, 3:53 PM