Feature idea for ColdFusion

Published: {ts '2013-12-24 00:00:00'}
Author: Steven Neiland
Site Url: http://www.neiland.net/article/feature-idea-for-coldfusion/

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.