PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

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