Created
January 21, 2011 00:40
-
-
Save ejhayes/789029 to your computer and use it in GitHub Desktop.
proxyObj.cfc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
this.name="cloudfile"; | |
this.setter = new cfc.settings(); | |
function onRequestStart(){ | |
// do nothing, except disable debugging output--sadly this isn't cfscript enabled yet, so i just wrapped it | |
if(StructKeyExists(url,"init")){ | |
onApplicationStart(); | |
} | |
//this.setter.disableOutput(); | |
} | |
function onApplicationStart(){ | |
//whatever | |
application.cloudfile = new cfc.cloudfile(); | |
application.proxy = new proxyObj(); | |
} | |
// most errors may need to be handled here | |
function onError(any Exception){ | |
if( structKeyExists(Exception,"Func") ){ | |
// prep the args | |
local.arguments = Duplicate(URL); | |
StructAppend(local.Arguments, form); | |
// and call the missing method | |
WriteOutput(SerializeJSON(application.proxy.onMissingMethod(local.arguments.method, local.arguments))); | |
} else { | |
WriteOutput(arguments.Exception.type); | |
} | |
return; | |
} | |
// calling an invalid location should just return a fail | |
function onMissingTemplate(string targetPage){ | |
this.setter.disableOutput(); | |
WriteOutput(arguments.targetPage & " does not exist"); | |
return true; | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
function init(){ | |
this.time = now(); | |
} | |
function getProducts(){ | |
return [1,2,8,9,7]; | |
} | |
function getCd(){ | |
return this.time; | |
} | |
function onMissingMethod(string MethodName, struct MethodArguments){ | |
// do something | |
return "missing method"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfcomponent> | |
<cffunction name="onMissingMethod" access="remote"> | |
<cfargument type="string" name="MethodName"> | |
<cfargument type="struct" name="MethodArguments"> | |
<cfset var ret = "" /> | |
<cfinvoke component="#application.cloudfile#" method="#arguments.MethodName#" argumentCollection="#arguments.MethodArguments#" returnvariable="ret"> | |
<cfreturn ret /> | |
</cffunction> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The point of this is to persist an object in the application scope and force all requests to go through a blank proxy. In an attempt to avoid using evaluate, I had to write an old style onmissingmethod function inside of another proxy object that will get called whenever a function tries to be called. I ran some basic tests and this seemed pretty quick, but overall it seems like a lot of indirection and overhead for every call, all at the expense of reducing redundant code. Anyways, this was just an idea I was working on, but decided to throw in the trash for the time being--I'm keeping it here in the event that I want to look back at this option in the future.
Based on the ideas from: http://www.bennadel.com/blog/1568-Using-OnMissingMethod-With-Remote-Access-ColdFusion-Components.htm and http://www.bennadel.com/blog/1943-Generic-Invocation-Wrapper-For-Core-ColdFusion-Functions.htm