OOPhoto - Starting With My Base Model Object

<cfcomponent
	output="false"
	hint="I provide base functionality for all primary model objects.">
 
	<!---
		Create a variables instance scope. All "object-specific" data will be
		stored in this scope. All other items will be stored directly in the
		VARIABLES scope.
	--->
	<cfset VARIABLES.Instance = {} />
 
 
	<cffunction
		name="Get"
		access="public"
		returntype="any"
		output="false"
		hint="I return data from the instance properties.">
 
		<!--- Define arguments. --->
		<cfargument
			name="Property"
			type="string"
			required="true"
			hint="I am the property that is being returned."
			/>
 
		<!--- Define the local scope. --->
		<cfset var LOCAL = {} />
 
 
		<!---
			Check first to see if there is an overriding method for this value.
			All overriding methods must be private (scoped to VARIABLES) and must
			start with 'Get.'
		--->
		<cfif StructKeyExists( VARIABLES, "Get#ARGUMENTS.Property#" )>
 
			<!--- Store the return value of the override invokation. --->
			<cfinvoke
				method="Get#ARGUMENTS.Property#"
				argumentcollection="#ARGUMENTS#"
				returnvariable="LOCAL.Return"
				/>
 
			<!--- Return the intermediary value. --->
			<cfreturn LOCAL.Return />
 
		<!--- Check to see if this property is valid. --->
		<cfelseif StructKeyExists( VARIABLES.Instance, ARGUMENTS.Property )>
 
			<!--- Return the property. --->
			<cfreturn VARIABLES.Instance[ ARGUMENTS.Property ] />
 
		<cfelse>
 
			<!---
				Something went wrong - a property was requested that cannot be
				located in any fashion. Throw an error.
			--->
			<cfthrow
				type="OOPhoto.BaseService.InvalidProperty"
				message="The property you requested could not be found."
				detail="The property you requested, #UCase( ARGUMENTS.Property )#, could not be accessed."
				/>
 
		</cfif>
	</cffunction>
 
 
	<cffunction
		name="InjectDependency"
		access="package"
		returntype="any"
		output="false"
		hint="I inject dependency objecst into the VARIABLES scope of the extending Model object.">
 
		<!--- Define arguments. --->
		<cfargument
			name="Property"
			type="string"
			required="true"
			hint="The key at which the dependency will be stored."
			/>
 
		<cfargument
			name="Dependency"
			type="any"
			required="true"
			hint="The dependency object that is being injected into the extending service object."
			/>
 
		<!--- Inject the dependency object. --->
		<cfset VARIABLES[ ARGUMENTS.Property ] = ARGUMENTS.Dependency />
 
		<!--- Return this object for method chaining. --->
		<cfreturn THIS />
	</cffunction>
 
 
	<cffunction
		name="OnMissingMethod"
		access="public"
		returntype="any"
		output="false"
		hint="I handle calls to methods that do not exist.">
 
		<!--- Define arguments. --->
		<cfargument
			name="MissingMethodName"
			type="string"
			required="true"
			hint="I am the name of the method that was called."
			/>
 
		<cfargument
			name="MissingMethodArguments"
			type="struct"
			required="true"
			hint="I am the arguments that were passed to the missing method."
			/>
 
		<!--- Define the local scope. --->
		<cfset var LOCAL = {} />
 
		<!--- Check to see if the method name is a valid Get method. --->
		<cfif REFindNoCase( "^Get.+", ARGUMENTS.MissingMethodName )>
 
			<!--- Get the property name from the method. --->
			<cfset LOCAL.Property = REReplace(
				ARGUMENTS.MissingMethodName,
				"^.{3}",
				"",
				"one"
				) />
 
			<!--- Return the "Get" of this property. --->
			<cfreturn THIS.Get( LOCAL.Property ) />
 
		<!--- Check to see if the method name is a valid Set method. --->
		<cfelseif REFindNoCase( "^Set.+", ARGUMENTS.MissingMethodName )>
 
			<!--- Get the property name from the method. --->
			<cfset LOCAL.Property = REReplace(
				ARGUMENTS.MissingMethodName,
				"^.{3}",
				"",
				"one"
				) />
 
			<!--- Return the "Set" of this property. --->
			<cfreturn THIS.Set(
				LOCAL.Property,
				ARGUMENTS.MissingMethodArguments[ 1 ]
				) />
 
		<cfelse>
 
			<!--- If we got this far than the method was truly invalid. Throw an error. --->
			<cfthrow
				type="OOPhoto.BaseService.InvalidMethod"
				message="The method you requested could not be found."
				detail="The method you requested, #UCase( ARGUMENTS.MissingMethodName )#, could not be accessed."
				/>
 
		</cfif>
	</cffunction>
 
 
	<cffunction
		name="Set"
		access="public"
		returntype="any"
		output="false"
		hint="I store data to the instance properties.">
 
		<!--- Define arguments. --->
		<cfargument
			name="Property"
			type="string"
			required="true"
			hint="I am the property that is being set."
			/>
 
		<cfargument
			name="Value"
			type="any"
			required="true"
			hint="I am the value being stored." />
 
		<!--- Define the local scope. --->
		<cfset var LOCAL = {} />
 
 
		<!---
			Check first to see if there is an overriding method for this value.
			All overriding methods must be private (scoped to VARIABLES) and must
			start with 'Set.'
		--->
		<cfif StructKeyExists( VARIABLES, "Set#ARGUMENTS.Property#" )>
 
			<!--- Use the override invokation. --->
			<cfinvoke
				method="Set#ARGUMENTS.Property#"
				value="#ARGUMENTS.Value#"
				/>
 
		<!--- Check to see if this property is valid. --->
		<cfelseif StructKeyExists( VARIABLES.Instance, ARGUMENTS.Property )>
 
			<!--- Set the property. --->
			<cfset VARIABLES.Instance[ ARGUMENTS.Property ] = ARGUMENTS.Value />
 
		<cfelse>
 
			<!---
				Something went wrong - a property was requested that cannot be
				located in any fashion. Throw an error.
			--->
			<cfthrow
				type="OOPhoto.BaseService.InvalidProperty"
				message="The property you requested could not be found."
				detail="The property you requested, #UCase( ARGUMENTS.Property )#, could not be accessed."
				/>
 
		</cfif>
 
		<!--- Always return the THIS scope so that this method can be chained. --->
		<cfreturn THIS />
	</cffunction>
 
</cfcomponent>

For Cut-and-Paste