root / framework / tags / fusebox5RC1 / fusebox5.cfm

Revision 202, 11.5 kB (checked in by scorfield, 3 years ago)

Fixes #82 by moving all 'special' request variables into request.fusebox and moving the tracing machinery into myFusebox (and therefore deleting the fuseboxTrace component).

Line 
1<cftry><cfsilent> <!--- on one line to avoid leading whitespace --->
2<!---
3Fusebox Software License
4Version 1.0
5
6Copyright (c) 2003, 2004, 2005, 2006 The Fusebox Corporation. All rights reserved.
7
8Redistribution and use in source and binary forms, with or without modification, are permitted
9provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this list of conditions
12   and the following disclaimer.
13
142. Redistributions in binary form or otherwise encrypted form must reproduce the above copyright
15   notice, this list of conditions and the following disclaimer in the documentation and/or other
16   materials provided with the distribution.
17
183. The end-user documentation included with the redistribution, if any, must include the following
19   acknowledgment:
20
21   "This product includes software developed by the Fusebox Corporation (http://www.fusebox.org/)."
22
23   Alternately, this acknowledgment may appear in the software itself, if and wherever such
24   third-party acknowledgments normally appear.
25
264. The names "Fusebox" and "Fusebox Corporation" must not be used to endorse or promote products
27   derived from this software without prior written (non-electronic) permission. For written
28   permission, please contact fusebox@fusebox.org.
29
305. Products derived from this software may not be called "Fusebox", nor may "Fusebox" appear in
31   their name, without prior written (non-electronic) permission of the Fusebox Corporation. For
32   written permission, please contact fusebox@fusebox.org.
33
34If one or more of the above conditions are violated, then this license is immediately revoked and
35can be re-instated only upon prior written authorization of the Fusebox Corporation.
36
37THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39DISCLAIMED. IN NO EVENT SHALL THE FUSEBOX CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY
40DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
43STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
46-------------------------------------------------------------------------------
47
48This software consists of voluntary contributions made by many individuals on behalf of the
49Fusebox Corporation. For more information on Fusebox, please see <http://www.fusebox.org/>.
50
51--->
52
53<!--- FB5: allow "" default - FB41 required this variable: --->
54<cfparam name="variables.FUSEBOX_APPLICATION_PATH" type="string" default="" />
55<!--- FB5: application key - FB41 always uses 'fusebox': --->
56<cfparam name="variables.FUSEBOX_APPLICATION_KEY" type="string" default="fusebox" />
57
58<cfparam name="variables.attributes" type="struct" default="#structNew()#" />
59<cfset structAppend(attributes,URL,true) />
60<cfset structAppend(attributes,form,true) />
61
62<!--- FB5: myFusebox is an object but has FB41-compatible public properties --->
63<cfset myFusebox = createObject("component","myFusebox").init(FUSEBOX_APPLICATION_KEY,attributes) />
64<!--- FB5: indicates whether application was started on this request --->
65<cfset myFusebox.applicationStart = false />
66<!--- FB5: uses request.__fusebox for internal tracking of compiler / runtime operations: --->
67<cfset request.__fusebox = structNew() />
68<!---
69        complex condition allows FB5 to drop into a running FB41 site and force re-init because
70        FB41 application.fusebox will not have compileRequest() method - this should make upgrades
71        to FB5 easier!
72--->
73<cfif not structKeyExists(application,FUSEBOX_APPLICATION_KEY) or myFusebox.parameters.load>
74        <cflock name="#application.ApplicationName#_fusebox_#FUSEBOX_APPLICATION_KEY#" type="exclusive" timeout="300">
75                <cfif not structKeyExists(application,FUSEBOX_APPLICATION_KEY) or myFusebox.parameters.load>
76                        <!--- if it doesn't exisit or the user explicitly requested a load, it --->
77                        <cfif not structKeyExists(application,FUSEBOX_APPLICATION_KEY) or myFusebox.parameters.userProvidedLoadParameter>
78                                <!--- can't be conditional: we don't know the state of the debug flag yet --->
79                                <cfset myFusebox.trace("Fusebox","Creating Fusebox application object") />
80                                <cfset _fba = createObject("component","fuseboxApplication") />
81                                <cfset application[FUSEBOX_APPLICATION_KEY] = _fba />
82                                <cfset _fba.init(FUSEBOX_APPLICATION_KEY,FUSEBOX_APPLICATION_PATH,myFusebox) />
83                        <cfelse>
84                                <!--- can't be conditional: we don't know the state of the debug flag yet --->
85                                <cfset myFusebox.trace("Fusebox","Reloading Fusebox application object") />
86                                <cfset _fba = application[FUSEBOX_APPLICATION_KEY] />
87                                <!--- it exists and the load is implicit, not explicit (via user) so just reload XML --->
88                                <cfset _fba.reload(FUSEBOX_APPLICATION_KEY,FUSEBOX_APPLICATION_PATH,myFusebox) />
89                        </cfif>
90                        <!--- fix attributes precedence --->
91                        <cfif _fba.precedenceFormOrURL is "URL">
92                                <cfset structAppend(attributes,URL,true) />
93                        </cfif>
94                        <!--- set the default fuseaction if necessary --->
95                        <cfif not structKeyExists(attributes,_fba.fuseactionVariable) or attributes[_fba.fuseactionVariable] is "">
96                                <cfset attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction />
97                        </cfif>
98                        <!--- set this up for fusebox.appinit.cfm --->
99                        <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] />
100                        <!--- flag this as the first request for the application --->
101                        <cfset myFusebox.applicationStart = true />
102                        <!--- force parse after reload for consistency --->
103                        <cfset myFusebox.parameters.parse = true />
104                        <!--- need all of the above set before we attempt any compiles! --->
105                        <cfif myFusebox.parameters.parseall>
106                                <cfset _fba.compileAll(myFusebox) />
107                        </cfif>
108                        <!--- FB5: new appinit include file --->
109                        <cfif _fba.debug>
110                                <cfset myFusebox.trace("Fusebox","Including fusebox.appinit.cfm") />
111                        </cfif>
112                        <cftry>
113                                <cfinclude template="#_fba.getCoreToAppRootPath()#fusebox.appinit.cfm" />
114                        <cfcatch type="missinginclude" />
115                        </cftry>
116                <cfelse>
117                        <cfset _fba = application[FUSEBOX_APPLICATION_KEY] />
118                        <!--- fix attributes precedence --->
119                        <cfif _fba.precedenceFormOrURL is "URL">
120                                <cfset structAppend(attributes,URL,true) />
121                        </cfif>
122                        <!--- set the default fuseaction if necessary --->
123                        <cfif not structKeyExists(attributes,_fba.fuseactionVariable) or attributes[_fba.fuseactionVariable] is "">
124                                <cfset attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction />
125                        </cfif>
126                        <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] />
127                </cfif>
128        </cflock>
129<cfelse>
130        <cfset _fba = application[FUSEBOX_APPLICATION_KEY] />
131        <!--- fix attributes precedence --->
132        <cfif _fba.precedenceFormOrURL is "URL">
133                <cfset structAppend(attributes,URL,true) />
134        </cfif>
135        <!--- set the default fuseaction if necessary --->
136        <cfif not structKeyExists(attributes,_fba.fuseactionVariable) or attributes[_fba.fuseactionVariable] is "">
137                <cfset attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction />
138        </cfif>
139        <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] />
140</cfif>
141<!---
142        Fusebox 4.1 did not set attributes.fuseaction or default the fuseaction variable until
143        *after* fusebox.init.cfm had run. This made it hard for fusebox.init.cfm to do URL
144        rewriting. For Fusebox 5, we default the fuseaction variable and set attributes.fuseaction
145        before fusebox.init.cfm so it can rely on attributes.fuseaction and rewrite that. However,
146        in order to maintain backward compatibility, we need to allow fusebox.init.cfm to set
147        attributes[_fba.fuseactionVariable] and still have that reflected in attributes.fuseaction
148        and for that to actually be the request that gets processed.
149--->
150<cfif _fba.debug>
151        <cfset myFusebox.trace("Fusebox","Including fusebox.init.cfm") />
152</cfif>
153<cftry>
154        <cfset _fba_attr_fav = attributes[_fba.fuseactionVariable] />
155        <cfset _fba_attr_fa = attributes.fuseaction />
156        <cfinclude template="#_fba.getCoreToAppRootPath()#fusebox.init.cfm" />
157        <cfif attributes.fuseaction is not _fba_attr_fa>
158                <cfif attributes.fuseaction is not attributes[_fba.fuseactionVariable]>
159                        <cfif attributes[_fba.fuseactionVariable] is not _fba_attr_fav>
160                                <!--- inconsistent modification of both variables?!? --->
161                                <cfthrow type="fusebox.inconsistentFuseaction"
162                                                message="Inconsistent fuseaction variables"
163                                                detail="Both attributes.fuseaction and attributes[{fusebox}.fuseactionVariable] changed in fusebox.init.cfm so Fusebox doesn't know what to do with the values!" />
164                        <cfelse>
165                                <!--- ok, only attributes.fuseaction changed --->
166                                <cfset attributes[_fba.fuseactionVariable] = attributes.fuseaction />
167                        </cfif>
168                <cfelse>
169                        <!--- ok, they were both changed and they match --->
170                </cfif>
171        <cfelse>
172                <!--- attributes.fuseaction did not change --->
173                <cfif attributes[_fba.fuseactionVariable] is not _fba_attr_fav>
174                        <!--- make attributes.fuseaction match the other changed variable --->
175                        <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] />
176                <cfelse>
177                        <!--- ok, neither variable changed --->
178                </cfif>
179        </cfif>
180<cfcatch type="missinginclude" />
181</cftry>
182<!---
183        must special case development-circuit-load mode since it causes circuits to reload during
184        the compile (post-load) phase and therefore must be exclusive
185--->
186<cfif _fba.debug>
187        <cfset myFusebox.trace("Fusebox","Compiling requested fuseaction '#attributes.fuseaction#'") />
188</cfif>
189<cfif _fba.mode is "development-circuit-load">
190        <cflock name="#application.ApplicationName#_fusebox_#FUSEBOX_APPLICATION_KEY#" type="exclusive" timeout="300">
191                <cfset _parsedFileData = _fba.compileRequest(attributes.fuseaction,myFusebox) />
192        </cflock>
193<cfelse>
194        <cflock name="#application.ApplicationName#_fusebox_#FUSEBOX_APPLICATION_KEY#" type="readonly" timeout="300">
195                <cfset _parsedFileData = _fba.compileRequest(attributes.fuseaction,myFusebox) />
196        </cflock>
197</cfif>
198</cfsilent><cfprocessingdirective suppresswhitespace="true">
199<!---
200        readonly lock protects against including the parsed file while
201        another threading is writing it...
202--->
203<cfif myFusebox.parameters.execute>
204        <cfif _fba.debug>
205                <cfset myFusebox.trace("Fusebox","Including parsed file for '#attributes.fuseaction#'") />
206        </cfif>
207        <cftry>
208                <cflock name="#_parsedFileData.lockName#" type="readonly" timeout="30">
209                        <cfinclude template="#_parsedFileData.parsedFile#" />
210                </cflock>
211        <cfcatch type="missinginclude">
212                <cfif right(cfcatch.missingFileName, len(_parsedFileData.parsedName)) is _parsedFileData.parsedName>
213                        <cfthrow type="fusebox.missingParsedFile"
214                                        message="Parsed File or Directory not found."
215                                        detail="Attempting to execute the parsed file '#_parsedFileData.parsedName#' threw an error. This can occur if the parsed file does not exist in the parsed directory or if the parsed directory itself is missing." />
216                <cfelse>
217                        <cfrethrow />
218                </cfif>
219        </cfcatch>
220        </cftry>
221</cfif>
222</cfprocessingdirective>
223<cfcatch type="fusebox">
224        <cfif isDefined("_fba.debug") and _fba.debug and isDefined("myFusebox")>
225                <cfset myFusebox.trace("Fusebox","Caught Fusebox exception '#cfcatch.type#'") />
226        </cfif>
227        <cfif not isDefined("_fba.errortemplatesPath") or not _fba.handleFuseboxException(cfcatch)>
228                <cfrethrow />
229        </cfif>
230</cfcatch>
231</cftry>
232<cfset myFusebox.trace("Fusebox","Request completed") />
233<cfif isDefined("_fba.debug") and _fba.debug and isDefined("myFusebox")>
234        <cfoutput>#myFusebox.renderTrace()#</cfoutput>
235</cfif>
Note: See TracBrowser for help on using the browser.