PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/wheels/controller/processing.cfm

http://raihan.googlecode.com/
ColdFusion | 139 lines | 134 code | 5 blank | 0 comment | 24 complexity | e9e64d88a598fadd461f0f710ee0bf81 MD5 | raw file
  1<cffunction name="$processAction" returntype="boolean" access="public" output="false">
  2	<cfscript>
  3		var loc = {};
  4		loc.debug = application.wheels.showDebugInformation;
  5		if (loc.debug)
  6			$debugPoint("beforeFilters");
  7		// run verifications and before filters if they exist on the controller
  8		this.$runVerifications(action=params.action, params=params);
  9		// return immediately if an abort is issue from a verification
 10		if ($abortIssued())
 11			return true;
 12		this.$runFilters(type="before", action=params.action);
 13		
 14		// check to see if the controller params has changed and if so, instantiate the new controller and re-run filters and verifications
 15		if (params.controller != variables.$class.name)
 16			return false;
 17		
 18		if (loc.debug)
 19			$debugPoint("beforeFilters,action");
 20
 21		// only proceed to call the action if the before filter has not already rendered content
 22		if (!$performedRenderOrRedirect())
 23		{
 24			// call action on controller if it exists
 25			loc.actionIsCachable = false;
 26			if ($hasCachableActions() && flashIsEmpty() && StructIsEmpty(form))
 27			{
 28				loc.cachableActions = $cachableActions();
 29				loc.iEnd = ArrayLen(loc.cachableActions);
 30				for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
 31				{
 32					if (loc.cachableActions[loc.i].action == params.action || loc.cachableActions[loc.i].action == "*")
 33					{
 34						loc.actionIsCachable = true;
 35						loc.time = loc.cachableActions[loc.i].time;
 36						loc.static = loc.cachableActions[loc.i].static;
 37					}
 38				}
 39			}
 40			if (loc.actionIsCachable)
 41			{
 42				loc.category = "action";
 43				loc.key = $hashedKey(request.cgi.http_host, variables.$class.name, variables.params);
 44				loc.lockName = loc.category & loc.key;
 45				loc.conditionArgs = {};
 46				loc.conditionArgs.key = loc.key;
 47				loc.conditionArgs.category = loc.category;
 48				loc.executeArgs = {};
 49				loc.executeArgs.controller = loc.controller;
 50				loc.executeArgs.action = params.action;
 51				loc.executeArgs.key = loc.key;
 52				loc.executeArgs.time = loc.time;
 53				loc.executeArgs.static = loc.static;
 54				loc.executeArgs.category = loc.category;
 55				// get content from the cache if it exists there and set it to the request scope, if not the $callActionAndAddToCache function will run, caling the controller action (which in turn sets the content to the request scope)
 56				variables.$instance.response = $doubleCheckedLock(name=loc.lockName, condition="$getFromCache", execute="$callActionAndAddToCache", conditionArgs=loc.conditionArgs, executeArgs=loc.executeArgs);
 57			}
 58			else
 59			{
 60				$callAction(action=params.action);
 61			}
 62		}
 63
 64		// run after filters with surrounding debug points (don't run the filters if a delayed redirect will occur though)
 65		if (loc.debug)
 66			$debugPoint("action,afterFilters");
 67		if (!$performedRedirect())
 68			$runFilters(type="after", action=params.action);
 69		if (loc.debug)
 70			$debugPoint("afterFilters");
 71	</cfscript>
 72	<cfreturn true />
 73</cffunction>
 74
 75<cffunction name="$callAction" returntype="void" access="public" output="false">
 76	<cfargument name="action" type="string" required="true">
 77	<cfscript>
 78		var loc = {};
 79
 80		if (Left(arguments.action, 1) == "$" || ListFindNoCase(application.wheels.protectedControllerMethods, arguments.action))
 81			$throw(type="Wheels.ActionNotAllowed", message="You are not allowed to execute the `#arguments.action#` method as an action.", extendedInfo="Make sure your action does not have the same name as any of the built-in Wheels functions.");
 82
 83		if (StructKeyExists(this, arguments.action) && IsCustomFunction(this[arguments.action]))
 84		{
 85			$invoke(method=arguments.action);
 86		}
 87		else if (StructKeyExists(this, "onMissingMethod"))
 88		{
 89			loc.invokeArgs = {};
 90			loc.invokeArgs.missingMethodName = arguments.action;
 91			loc.invokeArgs.missingMethodArguments = {};
 92			$invoke(method="onMissingMethod", invokeArgs=loc.invokeArgs);
 93		}
 94
 95		if (!$performedRenderOrRedirect())
 96		{
 97			try
 98			{
 99				renderPage();
100			}
101			catch(Any e)
102			{
103				if (FileExists(ExpandPath("#application.wheels.viewPath#/#LCase(variables.$class.name)#/#LCase(arguments.action)#.cfm")))
104				{
105					$throw(object=e);
106				}
107				else
108				{
109					if (application.wheels.showErrorInformation)
110					{
111						$throw(type="Wheels.ViewNotFound", message="Could not find the view page for the `#arguments.action#` action in the `#variables.$class.name#` controller.", extendedInfo="Create a file named `#LCase(arguments.action)#.cfm` in the `views/#LCase(variables.$class.name)#` directory (create the directory as well if it doesn't already exist).");
112					}
113					else
114					{
115						$header(statusCode="404", statusText="Not Found");
116						$includeAndOutput(template="#application.wheels.eventPath#/onmissingtemplate.cfm");
117						$abort();
118					}
119				}
120			}
121		}
122	</cfscript>
123</cffunction>
124
125<cffunction name="$callActionAndAddToCache" returntype="string" access="public" output="false">
126	<cfargument name="action" type="string" required="true">
127	<cfargument name="static" type="boolean" required="true">
128	<cfargument name="time" type="numeric" required="true">
129	<cfargument name="key" type="string" required="true">
130	<cfargument name="category" type="string" required="true">
131	<cfscript>
132		$callAction(action=arguments.action);
133		if (arguments.static)
134			$cache(action="serverCache", timeSpan=$timeSpanForCache(arguments.time, "main"));
135		else
136			$addToCache(key=arguments.key, value=variables.$instance.response, time=arguments.time, category=arguments.category);
137	</cfscript>
138	<cfreturn response()>
139</cffunction>