MG3 Goodies: "Request Phase" architecture
Posted by Joe Rinehart at 3:45 PM
3 comments - Categories:
Model-Glue
One of the largest under-the-hood changes coming in Model-Glue 3 is what's known as a "request phase." It's not the easiest topic to write about, but it's making the framework much nicer to write, and it'll mean further extensibility and ease of modification for Model-Glue users.
The best way to understand it is to first see what happened upon invoking an event in earlier editions of Model-Glue. Basically, it went something like this:
- Add the modelglue.onRequestStart event and run results until the event queue is empty.
- Add the user's requested event and run results until the event queue is empty.
- Add the modelglue.onQueueComplete event and run the event queue until it's empty.
- Render views.
- Invoke the modelglue.onRequestEnd event and run the event queue.
- Render views.
It's a bit repetitive, and it was hard-coded into place. However, it's easy to see three phases in this: request initialization (onRequestStart), user request invocation (ends with onQueueComplete), and request termination (onRequestEnd).
In Model-Glue, the old flow will be in place, but the framework will be configured (via ColdSpring by default) with the various phases to execute as part of an event request.
Each "phase" is really just the execution of an initial event-handler, any queued results, and optional rendering/flushing of the view queue.
By defining internal event handlers (such as modelglue.onRequestStart) and dispatching them as parts of phases, under-the-hood Controllers can take over tasks such as populating the event context ("viewstate") and even configuring the framework itself.
New phases that have been identified:
- Request initialization will be a phase. In it, a request context is created (what most people know as "arguments.event") and populated with information from FORM, URL, etc.
- Loading of modules (event handlers and controllers) itself will be a phase, occurring after creation of an event context when the framework is in "development" mode or application is initialized.
What this means for you:
For most Model-Glue users, this means you'll have more "plug-in" points such as "onRequestStart." Expect to see points such as the following pop up:
* onSessionStart
* onSessionEnd
* onApplicationStart
* onDevelopmentRequestStart
* onEventContextCreation
* onMissingEvent
For those really looking to modify the heck out of Model-Glue, you'll be able to write your own request phase implementations. I'm not too sure what they'd do, but I'm sure someone will invent something!
Mark Drew wrote on 12/06/07 4:34 AM
This sounds like a great idea, since its horrible to have to start adding stuff just to application.cfc to do all of this!