/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. // check to see if the controller params has changed and if so, instantiate the new controller and re-run filters and verifications
  14. if (params.controller != variables.$class.name)
  15. return false;
  16. if (loc.debug)
  17. $debugPoint("beforeFilters,action");
  18. // only proceed to call the action if the before filter has not already rendered content
  19. if (!$performedRenderOrRedirect())
  20. {
  21. // call action on controller if it exists
  22. loc.actionIsCachable = false;
  23. if ($hasCachableActions() && flashIsEmpty() && StructIsEmpty(form))
  24. {
  25. loc.cachableActions = $cachableActions();
  26. loc.iEnd = ArrayLen(loc.cachableActions);
  27. for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
  28. {
  29. if (loc.cachableActions[loc.i].action == params.action || loc.cachableActions[loc.i].action == "*")
  30. {
  31. loc.actionIsCachable = true;
  32. loc.time = loc.cachableActions[loc.i].time;
  33. loc.static = loc.cachableActions[loc.i].static;
  34. }
  35. }
  36. }
  37. if (loc.actionIsCachable)
  38. {
  39. loc.category = "action";
  40. loc.key = $hashedKey(request.cgi.http_host, variables.$class.name, variables.params);
  41. loc.lockName = loc.category & loc.key;
  42. loc.conditionArgs = {};
  43. loc.conditionArgs.key = loc.key;
  44. loc.conditionArgs.category = loc.category;
  45. loc.executeArgs = {};
  46. loc.executeArgs.controller = loc.controller;
  47. loc.executeArgs.action = params.action;
  48. loc.executeArgs.key = loc.key;
  49. loc.executeArgs.time = loc.time;
  50. loc.executeArgs.static = loc.static;
  51. loc.executeArgs.category = loc.category;
  52. // 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)
  53. variables.$instance.response = $doubleCheckedLock(name=loc.lockName, condition="$getFromCache", execute="$callActionAndAddToCache", conditionArgs=loc.conditionArgs, executeArgs=loc.executeArgs);
  54. }
  55. else
  56. {
  57. $callAction(action=params.action);
  58. }
  59. }
  60. // run after filters with surrounding debug points (don't run the filters if a delayed redirect will occur though)
  61. if (loc.debug)
  62. $debugPoint("action,afterFilters");
  63. if (!$performedRedirect())
  64. $runFilters(type="after", action=params.action);
  65. if (loc.debug)
  66. $debugPoint("afterFilters");
  67. </cfscript>
  68. <cfreturn true />
  69. </cffunction>
  70. <cffunction name="$callAction" returntype="void" access="public" output="false">
  71. <cfargument name="action" type="string" required="true">
  72. <cfscript>
  73. var loc = {};
  74. if (Left(arguments.action, 1) == "$" || ListFindNoCase(application.wheels.protectedControllerMethods, arguments.action))
  75. $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.");
  76. if (StructKeyExists(this, arguments.action) && IsCustomFunction(this[arguments.action]))
  77. {
  78. $invoke(method=arguments.action);
  79. }
  80. else if (StructKeyExists(this, "onMissingMethod"))
  81. {
  82. loc.invokeArgs = {};
  83. loc.invokeArgs.missingMethodName = arguments.action;
  84. loc.invokeArgs.missingMethodArguments = {};
  85. $invoke(method="onMissingMethod", invokeArgs=loc.invokeArgs);
  86. }
  87. if (!$performedRenderOrRedirect())
  88. {
  89. try
  90. {
  91. renderPage();
  92. }
  93. catch(Any e)
  94. {
  95. if (FileExists(ExpandPath("#application.wheels.viewPath#/#LCase(variables.$class.name)#/#LCase(arguments.action)#.cfm")))
  96. {
  97. $throw(object=e);
  98. }
  99. else
  100. {
  101. if (application.wheels.showErrorInformation)
  102. {
  103. $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).");
  104. }
  105. else
  106. {
  107. $header(statusCode="404", statusText="Not Found");
  108. $includeAndOutput(template="#application.wheels.eventPath#/onmissingtemplate.cfm");
  109. $abort();
  110. }
  111. }
  112. }
  113. }
  114. </cfscript>
  115. </cffunction>
  116. <cffunction name="$callActionAndAddToCache" returntype="string" access="public" output="false">
  117. <cfargument name="action" type="string" required="true">
  118. <cfargument name="static" type="boolean" required="true">
  119. <cfargument name="time" type="numeric" required="true">
  120. <cfargument name="key" type="string" required="true">
  121. <cfargument name="category" type="string" required="true">
  122. <cfscript>
  123. $callAction(action=arguments.action);
  124. if (arguments.static)
  125. $cache(action="serverCache", timeSpan=$timeSpanForCache(arguments.time, "main"));
  126. else
  127. $addToCache(key=arguments.key, value=variables.$instance.response, time=arguments.time, category=arguments.category);
  128. </cfscript>
  129. <cfreturn response()>
  130. </cffunction>