/SampleApplication/ColdBox3/model/abstract/AbstractHandler.cfc

http://github.com/bobsilverberg/ValidateThisColdBoxPlugin · ColdFusion CFScript · 51 lines · 36 code · 2 blank · 13 comment · 8 complexity · 754004edc805412bc3b46aa3fabbdc8b MD5 · raw file

  1. /**
  2. * I am an abstract handler
  3. */
  4. component extends="coldbox.system.EventHandler"
  5. {
  6. /**
  7. * I am a dynamic finder. Useful for dynamically creating getters for instance variables.
  8. * For example:
  9. * getFooService will call getModel( "FooService ")
  10. * getFooPlugin will call getPlugin( "Foo" )
  11. */
  12. public any function onMissingMethod( required string MissingMethodName, required struct MissingMethodArguments )
  13. {
  14. var methodtype = Left( arguments.MissingMethodName, 3 );
  15. var requested = Replace( arguments.MissingMethodName, methodtype, "" );
  16. var result = "";
  17. switch ( methodtype )
  18. {
  19. case "get":
  20. if ( StructKeyExists( instance, requested ) )
  21. {
  22. // defined with cfproperty so just return value
  23. result = instance[ requested ];
  24. }
  25. else
  26. {
  27. // not defined with cfproperty
  28. if ( ReFindNoCase( "service$", requested ) != 0 )
  29. {
  30. // requesting a service object so get it from the model
  31. result = getModel( requested );
  32. }
  33. else if ( ReFindNoCase( "plugin$", requested ) != 0 )
  34. {
  35. // requesting a plugin object so get it from the plugins
  36. result = getPlugin( requested, StructCount( arguments.MissingMethodArguments ) != 0 );
  37. }
  38. else
  39. {
  40. throw( type='AbstractHandler.onMissingMethod', message='Unknown variable #requested#', detail='The onMissingMethod can not find a value to return' );
  41. }
  42. }
  43. break;
  44. default:
  45. throw( type='AbstractHandler.onMissingMethod', message='Unknown method #arguments.MissingMethodName#', detail='The method #arguments.MissingMethodName# does not exist' );
  46. }
  47. return result;
  48. }
  49. }