Feature idea for ColdFusion

Author: Steven Neiland
Published:

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

So I had an idea a few months ago for some behavior I would like to see added to ColdFusion. Now how feasible some of this would be to add I am not sure, but I think it could be very useful. Maybe if I'm good Adobe or Railo will add this for my Christmas stocking next year ;-)

Basically what I imagine is to borrow some of the behavior that FW/1 adds to the controller components. i.e. Have a series of optional functions that if defined would run every time a component (or component object) has a method invoked. These would essentially give some of the same abilities that AOP frameworks give without needing the AOP framework.

The logic

These functions would be: onCFCStart, onMethodStart, onMethodEnd and onCFCEnd. In addition these could be defined in the Application.cfc file to serve as global method. The logic would be as follows.

Application.cfc: onCFCStart:
Runs first when a component is called.

Arguments Received:

  • caller: Template or cfc name that invoked the component
  • component: The name of the component being invoked
  • method: The method being invoked on the component
  • methodAttributes: Meta data about the method being invoked (useful for logging)
  • argumentCollection: The arguments being passed to the invoked method

{component}.cfc: onCFCStart:

Runs once each time a component method is invoked from an outside source (another component or template). Example use would be to run validation that a given userId is authorized to call a named method.

Arguments Received:

  • method
  • methodAttributes
  • argumentCollection

{component}.cfc: onMethodStart:
Not to be confused with the init function. This function/method runs before each user method that is called within that component and that request. Should receive and arguments scope of the target method and share the same local scope.

Arguments Received:

  • method
  • methodAttributes
  • argumentCollection

{component}.cfc: method:

{component}.cfc: onMethodEnd:
Runs after each method that is called within that request. Should receive the argument scope, share local scope and passthru the return value. Example usage would be post processing/logging

Arguments Received:

  • method
  • methodAttributes
  • argumentCollection
  • methodResult

onMissingMethod: As currently implemented.

{component}.cfc: onCFCEnd:
Runs after all other methods have completed running

Arguments Received:

  • method
  • methodAttributes
  • argumentCollection
  • finalResult

Application.cfc: onCFCEnd:
Runs after a component is finished.

Arguments Received:

  • caller
  • component
  • method
  • methodAttributes
  • argumentCollection

Finally it would be useful if getMetaData() also returned the name of the function from which another function was called.

Update: Vote for this feature

I have now created feature requests for ColdFusion and Railo. Please vote if you think this idea has merit.

Reader Comments

Adam Cameron's Gravatar
Adam Cameron
Tuesday, December 24, 2013 at 10:54:35 AM Coordinated Universal Time

AOP baked right into the language? That'd be well cool!

Have you raised an enhancement request for this?

--
Adam

Steven Neiland's Gravatar
Steven Neiland
Tuesday, December 24, 2013 at 11:08:28 AM Coordinated Universal Time

Not yet. I only just finished working out the details in my mind last night. Will be doing that today.

Chris Weller's Gravatar
Chris Weller
Wednesday, December 25, 2013 at 10:35:12 PM Coordinated Universal Time

nice suggestion. I up-voted it. This is one of the big selling features for me in FW/1.

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain advertisments or appear to be created for the purpose of link building, will not be published.

Archives Blog Listing