PageRenderTime 12ms CodeModel.GetById 7ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/events/onapplicationstart.cfm

http://cfwheels.googlecode.com/
ColdFusion | 122 lines | 108 code | 14 blank | 0 comment | 20 complexity | a10b36a86eae356a444f0eda51ea00f2 MD5 | raw file
  1<cffunction name="onApplicationStart" returntype="void" access="public" output="false">
  2	<cfscript>
  3		var loc = {};
  4
  5		// abort if called from incorrect file
  6		$abortInvalidRequest();
  7
  8		// setup the wheels storage struct for the current request
  9		$initializeRequestScope();
 10
 11		// set or reset all settings but make sure to pass along the reload password between forced reloads with "reload=x"
 12		if (StructKeyExists(application, "wheels") && StructKeyExists(application.wheels, "reloadPassword"))
 13			loc.oldReloadPassword = application.wheels.reloadPassword;
 14		application.wheels = {};
 15		if (StructKeyExists(loc, "oldReloadPassword"))
 16			application.wheels.reloadPassword = loc.oldReloadPassword;
 17
 18		// check and store server engine name, throw error if using a version that we don't support
 19		// really need to refactor this into a method
 20		if (StructKeyExists(server, "railo"))
 21		{
 22			application.wheels.serverName = "Railo";
 23			application.wheels.serverVersion = server.railo.version;
 24			loc.minimumServerVersion = "3.1.2.020";
 25		}
 26		else
 27		{
 28			application.wheels.serverName = "Adobe ColdFusion";
 29			application.wheels.serverVersion = server.coldfusion.productversion;
 30			loc.minimumServerVersion = "8,0,1,0";
 31		}
 32
 33		if (!$checkMinimumVersion(application.wheels.serverVersion, loc.minimumServerVersion))
 34		{
 35			$throw(type="Wheels.EngineNotSupported", message="#application.wheels.serverName# #application.wheels.serverVersion# is not supported by Wheels.", extendedInfo="Please upgrade to version #loc.minimumServerVersion# or higher.");
 36		}
 37
 38		// copy over the cgi variables we need to the request scope (since we use some of these to determine URL rewrite capabilities we need to be able to access them directly on application start for example)
 39		request.cgi = $cgiScope();
 40
 41		// set up containers for routes, caches, settings etc
 42		application.wheels.version = "1.2 Beta 1";
 43		application.wheels.controllers = {};
 44		application.wheels.models = {};
 45		application.wheels.existingHelperFiles = "";
 46		application.wheels.existingLayoutFiles = "";
 47		application.wheels.existingObjectFiles = "";
 48		application.wheels.nonExistingHelperFiles = "";
 49		application.wheels.nonExistingLayoutFiles = "";
 50		application.wheels.nonExistingObjectFiles = "";
 51		application.wheels.routes = [];
 52		application.wheels.namedRoutePositions = {};
 53		application.wheels.mixins = {};
 54		application.wheels.vendor = {};
 55
 56		// set up paths to various folders in the framework
 57		application.wheels.webPath = Replace(request.cgi.script_name, Reverse(spanExcluding(Reverse(request.cgi.script_name), "/")), "");
 58		application.wheels.rootPath = "/" & ListChangeDelims(application.wheels.webPath, "/", "/");
 59		application.wheels.rootcomponentPath = ListChangeDelims(application.wheels.webPath, ".", "/");
 60		application.wheels.wheelsComponentPath = ListAppend(application.wheels.rootcomponentPath, "wheels", ".");
 61		application.wheels.configPath = "config";
 62		application.wheels.eventPath = "events";
 63		application.wheels.filePath = "files";
 64		application.wheels.imagePath = "images";
 65		application.wheels.javascriptPath = "javascripts";
 66		application.wheels.modelPath = "models";
 67		application.wheels.modelComponentPath = "models";
 68		application.wheels.pluginPath = "plugins";
 69		application.wheels.pluginComponentPath = "plugins";
 70		application.wheels.stylesheetPath = "stylesheets";
 71		application.wheels.viewPath = "views";
 72
 73		// set environment either from the url or the developer's environment.cfm file
 74		if (StructKeyExists(URL, "reload") && !IsBoolean(URL.reload) && Len(url.reload) && StructKeyExists(application.wheels, "reloadPassword") && (!Len(application.wheels.reloadPassword) || (StructKeyExists(URL, "password") && URL.password == application.wheels.reloadPassword)))
 75			application.wheels.environment = URL.reload;
 76		else
 77			$include(template="#application.wheels.configPath#/environment.cfm");
 78
 79		// load wheels settings
 80		$include(template="wheels/events/onapplicationstart/settings.cfm");
 81
 82		// load general developer settings first, then override with environment specific ones
 83		$include(template="#application.wheels.configPath#/settings.cfm");
 84		$include(template="#application.wheels.configPath#/#application.wheels.environment#/settings.cfm");
 85
 86		if(application.wheels.clearQueryCacheOnReload)
 87		{
 88			$objectcache(action="clear");
 89		}
 90
 91		// add all public controller / view methods to a list of methods that you should not be allowed to call as a controller action from the url
 92		loc.allowedGlobalMethods = "get,set,addroute,addDefaultRoutes";
 93		loc.protectedControllerMethods = StructKeyList($createObjectFromRoot(path=application.wheels.controllerPath, fileName="Wheels", method="$initControllerClass"));
 94		application.wheels.protectedControllerMethods = "";
 95		loc.iEnd = ListLen(loc.protectedControllerMethods);
 96		for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
 97		{
 98			loc.method = ListGetAt(loc.protectedControllerMethods, loc.i);
 99			if (Left(loc.method, 1) != "$" && !ListFindNoCase(loc.allowedGlobalMethods, loc.method))
100				application.wheels.protectedControllerMethods = ListAppend(application.wheels.protectedControllerMethods, loc.method);
101		}
102
103		// reload the plugins each time we reload the application
104		$loadPlugins();
105		
106		// allow developers to inject plugins into the application variables scope
107		if (!StructIsEmpty(application.wheels.mixins))
108			$include(template="wheels/plugins/injection.cfm");
109
110		// load developer routes and adds the default wheels routes (unless the developer has specified not to)
111		$loadRoutes();
112
113		// create the dispatcher that will handle all incoming requests
114		application.wheels.dispatch = $createObjectFromRoot(path="wheels", fileName="Dispatch", method="$init");
115
116		// create the cache object
117		application.wheels.cache = $createObjectFromRoot(path="wheels", fileName="Cache", method="init");
118
119		// run the developer's on application start code
120		$include(template="#application.wheels.eventPath#/onapplicationstart.cfm");
121	</cfscript>
122</cffunction>