public
Description: Shade is a state machine (or workflow) engine for ColdFusion business objects.
Homepage:
Clone URL: git://github.com/ryanwood/shade.git
shade / State.cfc
100644 47 lines (39 sloc) 1.728 kb
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
<cfcomponent displayname="State" output="false">
 
<cfset instance = structNew() />
 
<cffunction name="init" access="public" output="false">
<cfargument name="name" type="string" required="true" />
<cfscript>
instance.name = arguments.name;
</cfscript>
<cfreturn this />
</cffunction>
 
<cffunction name="getName" returntype="string" access="public" output="false">
<cfreturn instance.name />
</cffunction>
 
<cffunction name="before" returntype="boolean" access="public" output="false">
<cfargument name="obj" required="true" />
<cfset invokeCallback('beforeAction', arguments.obj) />
<cfreturn invokeCallback('before#getName()#Action', arguments.obj) />
</cffunction>
 
<cffunction name="after" returntype="void" access="public" output="false">
<cfargument name="obj" required="true" />
<cfset invokeCallback('after#getName()#Action', arguments.obj) />
<cfset invokeCallback('afterAction', arguments.obj) />
</cffunction>
 
<cffunction name="exit" returntype="void" access="public" output="false">
<cfargument name="obj" required="true" />
<cfset invokeCallback('exit#getName()#Action', arguments.obj) />
<cfset invokeCallback('exitAction', arguments.obj) />
</cffunction>
 
<cffunction name="invokeCallback" returntype="boolean" access="private" output="false">
<cfargument name="callback" type="string" required="true" />
<cfargument name="obj" required="true" />
<cfif structKeyExists(arguments.obj, arguments.callback)>
<cfinvoke component="#arguments.obj#" method="#arguments.callback#" returnvariable="result" />
<cfif isDefined('result') and isBoolean(result)>
<cfreturn result />
</cfif>
</cfif>
<cfreturn true />
</cffunction>
 
</cfcomponent>