| 1 | <!----------------------------------------------------------------------- |
|---|
| 2 | ******************************************************************************** |
|---|
| 3 | Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp |
|---|
| 4 | www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com |
|---|
| 5 | ******************************************************************************** |
|---|
| 6 | |
|---|
| 7 | Author : Luis Majano |
|---|
| 8 | Date : January 18, 2007 |
|---|
| 9 | Description : |
|---|
| 10 | This cfc takes care of request context operations such as |
|---|
| 11 | creating new contexts, retrieving, clearing, etc. |
|---|
| 12 | |
|---|
| 13 | Modification History: |
|---|
| 14 | 01/18/2007 - Created |
|---|
| 15 | -----------------------------------------------------------------------> |
|---|
| 16 | <cfcomponent name="requestService" output="false"> |
|---|
| 17 | |
|---|
| 18 | <!------------------------------------------- CONSTRUCTOR -------------------------------------------> |
|---|
| 19 | |
|---|
| 20 | <cffunction name="init" access="public" output="false" returntype="requestService" hint="Constructor"> |
|---|
| 21 | <cfargument name="controller" type="any" required="true"> |
|---|
| 22 | <cfscript> |
|---|
| 23 | variables.controller = arguments.controller; |
|---|
| 24 | return this; |
|---|
| 25 | </cfscript> |
|---|
| 26 | </cffunction> |
|---|
| 27 | |
|---|
| 28 | <!------------------------------------------- PUBLIC -------------------------------------------> |
|---|
| 29 | |
|---|
| 30 | <cffunction name="requestCapture" access="public" returntype="any" output="false" hint="I capture a request."> |
|---|
| 31 | <cfscript> |
|---|
| 32 | var Context = createContext(); |
|---|
| 33 | var DebugPassword = controller.getSetting("debugPassword"); |
|---|
| 34 | |
|---|
| 35 | //Object Caching Garbage Collector |
|---|
| 36 | controller.getColdboxOCM().reap(); |
|---|
| 37 | |
|---|
| 38 | //Debug Mode Checks |
|---|
| 39 | if ( Context.valueExists("debugMode") and isBoolean(Context.getValue("debugMode")) ){ |
|---|
| 40 | if ( DebugPassword eq "") |
|---|
| 41 | controller.getDebuggerService().setDebugMode(Context.getValue("debugMode")); |
|---|
| 42 | else if ( Context.valueExists("debugpass") and CompareNoCase(DebugPassword,Context.getValue("debugpass")) eq 0 ) |
|---|
| 43 | controller.getDebuggerService().setDebugMode(Context.getValue("debugMode")); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | //Event Checks |
|---|
| 47 | //Default Event Definition |
|---|
| 48 | if ( not Context.valueExists("event")) |
|---|
| 49 | Context.setValue("event", controller.getSetting("DefaultEvent")); |
|---|
| 50 | //Event More Than 1 Check, grab the first event instance, other's are discarded |
|---|
| 51 | if ( listLen(Context.getValue("event")) gte 2 ) |
|---|
| 52 | Context.setValue("event", getToken(Context.getValue("event"),2,",")); |
|---|
| 53 | |
|---|
| 54 | //Set Request Context in storage |
|---|
| 55 | setContext(Context); |
|---|
| 56 | //Return Context |
|---|
| 57 | return getContext(); |
|---|
| 58 | </cfscript> |
|---|
| 59 | </cffunction> |
|---|
| 60 | |
|---|
| 61 | <cffunction name="getContext" access="public" output="false" returntype="any" hint="Get the Request Context"> |
|---|
| 62 | <cfscript> |
|---|
| 63 | if ( contextExists() ) |
|---|
| 64 | return request.cb_requestContext; |
|---|
| 65 | else |
|---|
| 66 | return createContext(); |
|---|
| 67 | </cfscript> |
|---|
| 68 | </cffunction> |
|---|
| 69 | |
|---|
| 70 | <cffunction name="setContext" access="public" output="false" returntype="void" hint="Set the Request Context"> |
|---|
| 71 | <cfargument name="Context" type="coldbox.system.beans.requestContext" required="true"> |
|---|
| 72 | <cfscript> |
|---|
| 73 | request.cb_requestContext = arguments.Context; |
|---|
| 74 | </cfscript> |
|---|
| 75 | </cffunction> |
|---|
| 76 | |
|---|
| 77 | <cffunction name="contextExists" access="public" output="false" returntype="boolean" hint="Does the request context exist"> |
|---|
| 78 | <cfscript> |
|---|
| 79 | return structKeyExists(request,"cb_requestContext"); |
|---|
| 80 | </cfscript> |
|---|
| 81 | </cffunction> |
|---|
| 82 | |
|---|
| 83 | <!------------------------------------------- PRIVATE -------------------------------------------> |
|---|
| 84 | |
|---|
| 85 | <cffunction name="createContext" access="private" output="false" returntype="any" hint="Creates a new request context object"> |
|---|
| 86 | <cfscript> |
|---|
| 87 | var DefaultLayout = ""; |
|---|
| 88 | var ViewLayouts = structNew(); |
|---|
| 89 | |
|---|
| 90 | if ( controller.settingExists("DefaultLayout") ){ |
|---|
| 91 | DefaultLayout = controller.getSetting("DefaultLayout"); |
|---|
| 92 | } |
|---|
| 93 | if ( controller.settingExists("ViewLayouts") ){ |
|---|
| 94 | ViewLayouts = controller.getSetting("ViewLayouts"); |
|---|
| 95 | } |
|---|
| 96 | return CreateObject("component","coldbox.system.beans.requestContext").init(FORM, URL, DefaultLayout, ViewLayouts); |
|---|
| 97 | </cfscript> |
|---|
| 98 | </cffunction> |
|---|
| 99 | |
|---|
| 100 | </cfcomponent> |
|---|