-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathMethodInvocation.cfc
132 lines (122 loc) · 3.68 KB
/
MethodInvocation.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* This object is used when implementing AOP advices. Each advice you create will implement
* a `invokeMethod()` and receive this object as an argument.
* You can then use any of the properties in this object to construct your advice.
* Please see the property documentation below to understand each of the properties.
* Just remember that in order to continue the execution of the Advised method you will need to call `proceed()`
*/
component accessors="true" {
/**
* The currently executing method
*/
property name="method";
/**
* The currently executing method arguments
*/
property name="args";
/**
* The current method metadata
*/
property name="methodMetadata";
/**
* The target of execution
*/
property name="target";
/**
* The target shortname
*/
property name="targetName";
/**
* The target wirebox mapping
*/
property name="targetMapping";
/**
* The AOP interceptors to execute
*/
property name="interceptors";
/**
* The current index of execution
*/
property name="interceptorIndex";
/**
* The number of interceptors applied
*/
property name="interceptorLen";
/**
* Constructor
*
* @method The method name that was intercepted
* @args The argument collection that was intercepted
* @methodMetadata The method metadata that was intercepted
* @target The target object reference that was intercepted
* @targetName The name of the target wired up
* @targetMapping The target's mapping object reference
* @targetMapping.doc_generic coldbox.system.ioc.config.Mapping
* @interceptors The array of interceptors for this invocation
*/
function init(
required method,
required args,
required methodMetadata,
required target,
required targetName,
required targetMapping,
required interceptors
){
// Method intercepted
variables.method = arguments.method;
// Arguments intercepted
variables.args = arguments.args;
// Method metadata
variables.methodMetadata = deserializeJSON( urlDecode( arguments.methodMetadata ) );
// Target intercepted
variables.target = arguments.target;
// Target name
variables.targetName = arguments.targetName;
// Target Mapping Reference
variables.targetMapping = arguments.targetMapping;
// Interceptor array chain
variables.interceptors = arguments.interceptors;
// Current index to start execution
variables.interceptorIndex = 1;
// Length of interceptor
variables.interceptorLen = arrayLen( arguments.interceptors );
return this;
}
/**
* Increment the interceptor index pointer
*
* @return MethodInvocation
*/
function incrementInterceptorIndex(){
variables.interceptorIndex++;
return this;
}
/**
* Set args
*
* @return MethodInvocation
*/
function setArgs( required args ){
variables.args = arguments.args;
return this;
}
/**
* Proceed execution of the method invocation
*/
function proceed(){
// We will now proceed with our interceptor execution chain or regular method pointer call
// execute the next interceptor in the chain
// Check Current Index against interceptor length
if ( variables.interceptorIndex <= variables.interceptorLen ) {
return variables.interceptors[ variables.interceptorIndex ].invokeMethod(
this.incrementInterceptorIndex()
);
}
// If we get here all interceptors have fired and we need to fire the original proxied method
return variables.target.$wbAOPInvokeProxy( method = variables.method, args = variables.args );
}
}