PageRenderTime 504ms CodeModel.GetById 301ms app.highlight 1ms RepoModel.GetById 201ms app.codeStats 0ms

/wheels/events/onrequeststart.cfm

http://cfwheels.googlecode.com/
ColdFusion | 77 lines | 71 code | 6 blank | 0 comment | 16 complexity | 626b119aa062cae76095e9401a2a5083 MD5 | raw file
 1<cffunction name="onRequestStart" returntype="void" access="public" output="false">
 2	<cfargument name="targetPage" type="any" required="true">
 3	<cfscript>
 4		// abort if called from incorrect file
 5		$abortInvalidRequest();
 6
 7		// need to setup the wheels struct up here since it's used to store debugging info below if this is a reload request
 8		$initializeRequestScope();
 9
10		// reload application by calling onApplicationStart if requested
11		if (StructKeyExists(URL, "reload") && (!StructKeyExists(application, "wheels") || !StructKeyExists(application.wheels, "reloadPassword") || !Len(application.wheels.reloadPassword) || (StructKeyExists(URL, "password") && URL.password == application.wheels.reloadPassword)))
12		{
13			$debugPoint("total,reload");
14			$simpleLock(execute="onApplicationStart", name="wheelsReloadLock", type="exclusive", timeout=180);
15		}
16
17		// run the rest of the request start code
18		$simpleLock(execute="$runOnRequestStart", executeArgs=arguments, name="wheelsReloadLock", type="readOnly", timeout=180);
19	</cfscript>
20</cffunction>
21
22<cffunction name="$runOnRequestStart" returntype="void" access="public" output="false">
23	<cfargument name="targetPage" type="any" required="true">
24	<cfscript>
25		var loc = {};
26	
27		if (application.wheels.showDebugInformation)
28		{
29			// if the first debug point has not already been set in a reload request we set it here
30			if (StructKeyExists(request.wheels, "execution"))
31				$debugPoint("reload");
32			else
33				$debugPoint("total");
34			$debugPoint("requestStart");
35			request.wheels.deprecation = [];
36		}
37
38		// copy over the cgi variables we need to the request scope unless it's already been done on application start
39		if (!StructKeyExists(request, "cgi"))
40			request.cgi = $cgiScope();
41		
42		// reload the plugins on each request if cachePlugins is set to false
43		if (!application.wheels.cachePlugins)
44			$loadPlugins();
45
46		// inject methods from plugins directly to Application.cfc
47		if (!StructIsEmpty(application.wheels.mixins))
48			$include(template="wheels/plugins/injection.cfm");
49
50		if (application.wheels.environment == "maintenance")
51		{
52			if (StructKeyExists(URL, "except"))
53				application.wheels.ipExceptions = URL.except;
54			if (!Len(application.wheels.ipExceptions) || !ListFind(application.wheels.ipExceptions, request.cgi.remote_addr))
55			{
56				$includeAndOutput(template="#application.wheels.eventPath#/onmaintenance.cfm");
57				$abort();
58			}
59		}
60
61		if (Right(arguments.targetPage, 4) == ".cfc")
62		{
63			StructDelete(this, "onRequest");
64			StructDelete(variables, "onRequest");
65		}
66
67		if (!application.wheels.cacheModelInitialization)
68			$simpleLock(name="modelLock", execute="$clearModelInitializationCache", type="exclusive");
69		if (!application.wheels.cacheControllerInitialization)
70			$simpleLock(name="controllerLock", execute="$clearControllerInitializationCache", type="exclusive");
71		if (!application.wheels.cacheRoutes)
72			$loadRoutes();
73		$include(template="#application.wheels.eventPath#/onrequeststart.cfm");
74		if (application.wheels.showDebugInformation)
75			$debugPoint("requestStart");
76	</cfscript>
77</cffunction>