Created
January 4, 2011 22:06
-
-
Save rip747/765532 to your computer and use it in GitHub Desktop.
cfmiddleware
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> | |
<cfset $class = {}> | |
<cffunction name="init"> | |
<cfargument name="relativePath" type="string" default="" hint="the relative component path from the webroot"> | |
<cfset $class.container = []> | |
<cfset $class.relativePath = arguments.relativePath> | |
</cffunction> | |
<cffunction name="use" hint="Adds the new middleware at the bottom of the middleware stack."> | |
</cffunction> | |
<cffunction name="insertBefore" hint="Adds the new middleware before the specified existing middleware in the middleware stack."> | |
</cffunction> | |
<cffunction name="insertAfter" hint="Adds the new middleware after the specified existing middleware in the middleware stack."> | |
</cffunction> | |
<cffunction name="swap" hint="Replaces the specified middleware with a new middleware"> | |
</cffunction> | |
<cffunction name="remove" hint="Removes a specified middleware"> | |
</cffunction> | |
<cffunction name="add" hint="Adds a middleware to the stack in a specified position"> | |
<cfargument name="middleware_name" required="true"> | |
<cfargument name="middleware_position" required="false" default="0"> | |
<cfset var loc = {}> | |
<cfset loc.middleware_name = arguments.middleware_name> | |
<cfset structDelete(arguments, "middleware")> | |
<cfset loc.middleware_position = arguments.middleware_position> | |
<cfset structDelete(arguments, "middleware")> | |
<cfset loc.s = {name=loc.middleware_name, args=duplicate(arguments)}> | |
<cfif loc.middleware_position eq 0> | |
<cfset loc.middleware_position = ArrayLen(stack())> | |
</cfif> | |
<cfset ArrayInsertAt($class.container, loc.middleware_position)> | |
</cffunction> | |
<cffunction name="position" hint="Returns the position of the specified middleware in the stack"> | |
<cfargument name="middleware_name"> | |
<cfset var loc = {}> | |
<cfset loc.stack = stack()> | |
<cfset loc.size = ArrayLen(loc.stack)> | |
<cfloop from="1" to="#loc.size#"> | |
</cffunction> | |
<cffunction name="clear" hint="Clears the middleware stack"> | |
<cfset ArrayClear($class.container)> | |
</cffunction> | |
<cffunction name="stack" hint="Returns the middleware stack."> | |
<cfreturn $class.container> | |
</cffunction> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment