A normal constructor with one optional argument for logging results:
<--- init ---><cffunctionname="init"output="false"access="public"returntype="any"hint="Constructor"> <cfargumentname="logResults"type="boolean"required="false"default="true"hint="Do we log results or not?"/> <cfscript> instance = { logResults = arguments.logResults }; return this; </cfscript></cffunction>
And our invokeMethod implementation:
<--- invokeMethod ---><cffunctionname="invokeMethod"output="false"access="public"returntype="any"hint="Invoke an AOP method invocation"><cfargumentname="invocation"required="true"hint="The method invocation object: wirebox.system.aop.MethodInvocation"><cfscript> var refLocal = {}; var debugString = "target: #arguments.invocation.getTargetName()#,method: #arguments.invocation.getMethod()#,arguments:#serializeJSON(arguments.invocation.getArgs())#";
// log incoming call log.debug(debugString); // proceed execution refLocal.results = arguments.invocation.proceed(); // result logging and returns if( structKeyExists(refLocal,"results") ){if( instance.logResults ){ log.debug("#debugString#, results:", refLocal.results); } return refLocal.results; }</cfscript></cffunction>
As you can see, the before advice part is what happens before the execution of the real method (or more aspects) occurrs. So everything before the call to arguments.invocation.proceed():