-
Notifications
You must be signed in to change notification settings - Fork 15
/
route.cfc
48 lines (37 loc) · 1.42 KB
/
route.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
<cfcomponent>
<cffunction name="init" access="public" returntype="void">
<cfargument name="pattern" type="string" required="yes">
<cfset var param = "" />
<cfset variables.params = structNew() />
<cfset variables.pattern = arguments.pattern />
<cfloop list="#structKeyList(arguments)#" index="param">
<cfif not listFindNoCase("pattern", param)>
<cfset structInsert(variables.params, param, arguments[param], true) />
</cfif>
</cfloop>
</cffunction>
<cffunction name="match" access="public" returntype="boolean">
<cfargument name="url" type="string" required="yes">
<cfset var i = 1 />
<cfset var expected = "" />
<cfset var found = "" />
<cfif listLen(variables.pattern, '/') NEQ listLen(arguments.url, '/')>
<cfreturn false />
</cfif>
<cfloop list="#variables.pattern#" index="expected" delimiters="/">
<cfset found = listGetAt(url, i, '/') />
<cfif found NEQ expected>
<cfif find(":", expected) EQ 1>
<cfset variables.params[right(expected, len(expected) - 1)] = found />
<cfelse>
<cfreturn false />
</cfif>
</cfif>
<cfset i = i + 1 />
</cfloop>
<cfreturn structKeyExists(params, 'controller') AND structKeyExists(params, 'action') />
</cffunction>
<cffunction name="getParams" access="public" returntype="struct">
<cfreturn variables.params />
</cffunction>
</cfcomponent>