/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. // abort if called from incorrect file
  5. $abortInvalidRequest();
  6. // setup the wheels storage struct for the current request
  7. $initializeRequestScope();
  8. // set or reset all settings but make sure to pass along the reload password between forced reloads with "reload=x"
  9. if (StructKeyExists(application, "wheels") && StructKeyExists(application.wheels, "reloadPassword"))
  10. loc.oldReloadPassword = application.wheels.reloadPassword;
  11. application.wheels = {};
  12. if (StructKeyExists(loc, "oldReloadPassword"))
  13. application.wheels.reloadPassword = loc.oldReloadPassword;
  14. // check and store server engine name, throw error if using a version that we don't support
  15. // really need to refactor this into a method
  16. if (StructKeyExists(server, "railo"))
  17. {
  18. application.wheels.serverName = "Railo";
  19. application.wheels.serverVersion = server.railo.version;
  20. loc.minimumServerVersion = "3.1.2.020";
  21. }
  22. else
  23. {
  24. application.wheels.serverName = "Adobe ColdFusion";
  25. application.wheels.serverVersion = server.coldfusion.productversion;
  26. loc.minimumServerVersion = "8,0,1,0";
  27. }
  28. if (!$checkMinimumVersion(application.wheels.serverVersion, loc.minimumServerVersion))
  29. {
  30. $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.");
  31. }
  32. // 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)
  33. request.cgi = $cgiScope();
  34. // set up containers for routes, caches, settings etc
  35. application.wheels.version = "1.2 Beta 1";
  36. application.wheels.controllers = {};
  37. application.wheels.models = {};
  38. application.wheels.existingHelperFiles = "";
  39. application.wheels.existingLayoutFiles = "";
  40. application.wheels.existingObjectFiles = "";
  41. application.wheels.nonExistingHelperFiles = "";
  42. application.wheels.nonExistingLayoutFiles = "";
  43. application.wheels.nonExistingObjectFiles = "";
  44. application.wheels.routes = [];
  45. application.wheels.namedRoutePositions = {};
  46. application.wheels.mixins = {};
  47. application.wheels.vendor = {};
  48. // set up paths to various folders in the framework
  49. application.wheels.webPath = Replace(request.cgi.script_name, Reverse(spanExcluding(Reverse(request.cgi.script_name), "/")), "");
  50. application.wheels.rootPath = "/" & ListChangeDelims(application.wheels.webPath, "/", "/");
  51. application.wheels.rootcomponentPath = ListChangeDelims(application.wheels.webPath, ".", "/");
  52. application.wheels.wheelsComponentPath = ListAppend(application.wheels.rootcomponentPath, "wheels", ".");
  53. application.wheels.configPath = "config";
  54. application.wheels.eventPath = "events";
  55. application.wheels.filePath = "files";
  56. application.wheels.imagePath = "images";
  57. application.wheels.javascriptPath = "javascripts";
  58. application.wheels.modelPath = "models";
  59. application.wheels.modelComponentPath = "models";
  60. application.wheels.pluginPath = "plugins";
  61. application.wheels.pluginComponentPath = "plugins";
  62. application.wheels.stylesheetPath = "stylesheets";
  63. application.wheels.viewPath = "views";
  64. // set environment either from the url or the developer's environment.cfm file
  65. 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)))
  66. application.wheels.environment = URL.reload;
  67. else
  68. $include(template="#application.wheels.configPath#/environment.cfm");
  69. // load wheels settings
  70. $include(template="wheels/events/onapplicationstart/settings.cfm");
  71. // load general developer settings first, then override with environment specific ones
  72. $include(template="#application.wheels.configPath#/settings.cfm");
  73. $include(template="#application.wheels.configPath#/#application.wheels.environment#/settings.cfm");
  74. if(application.wheels.clearQueryCacheOnReload)
  75. {
  76. $objectcache(action="clear");
  77. }
  78. // 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
  79. loc.allowedGlobalMethods = "get,set,addroute,addDefaultRoutes";
  80. loc.protectedControllerMethods = StructKeyList($createObjectFromRoot(path=application.wheels.controllerPath, fileName="Wheels", method="$initControllerClass"));
  81. application.wheels.protectedControllerMethods = "";
  82. loc.iEnd = ListLen(loc.protectedControllerMethods);
  83. for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
  84. {
  85. loc.method = ListGetAt(loc.protectedControllerMethods, loc.i);
  86. if (Left(loc.method, 1) != "$" && !ListFindNoCase(loc.allowedGlobalMethods, loc.method))
  87. application.wheels.protectedControllerMethods = ListAppend(application.wheels.protectedControllerMethods, loc.method);
  88. }
  89. // reload the plugins each time we reload the application
  90. $loadPlugins();
  91. // allow developers to inject plugins into the application variables scope
  92. if (!StructIsEmpty(application.wheels.mixins))
  93. $include(template="wheels/plugins/injection.cfm");
  94. // load developer routes and adds the default wheels routes (unless the developer has specified not to)
  95. $loadRoutes();
  96. // create the dispatcher that will handle all incoming requests
  97. application.wheels.dispatch = $createObjectFromRoot(path="wheels", fileName="Dispatch", method="$init");
  98. // create the cache object
  99. application.wheels.cache = $createObjectFromRoot(path="wheels", fileName="Cache", method="init");
  100. // run the developer's on application start code
  101. $include(template="#application.wheels.eventPath#/onapplicationstart.cfm");
  102. </cfscript>
  103. </cffunction>