<cfcomponent
output="false"
hint="Wraps an image to provide dot-notation image functionality and chaining.">
<cfset VARIABLES.Image = "" />
<cfset VARIABLES.Page = GetPageContext().GetPage() />
<cffunction
name="Init"
access="public"
returntype="any"
output="false"
hint="Returns an initialized image wrapper.">
<cfargument
name="Image"
type="any"
required="true"
hint="The ColdFusion image object that we are going to be modifying."
/>
<cfset VARIABLES.Image = ARGUMENTS.Image />
<cfreturn THIS />
</cffunction>
<cffunction
name="Get"
access="public"
returntype="any"
output="false"
hint="Returns the target image.">
<cfreturn VARIABLES.Image />
</cffunction>
<cffunction
name="OnMissingMethod"
access="public"
returntype="any"
output="false"
hint="Handles missing methods that allow us to trap and leverage the ColdFusion image functionality with as little effort as possible.">
<cfargument
name="MissingMethodName"
type="string"
required="true"
hint="The method that was called."
/>
<cfargument
name="MissingMethodArguments"
type="struct"
required="true"
hint="The arguments that were passed to the above mentioned method."
/>
<cfset var LOCAL = StructNew() />
<cfset LOCAL.Return = "{null}" />
<cfset LOCAL.MethodName = ("Image" & ARGUMENTS.MissingMethodName) />
<cfif StructKeyExists( GetFunctionList(), LOCAL.MethodName )>
<cfset LOCAL.Arguments = "VARIABLES.Image" />
<cfloop
index="LOCAL.ArgumentIndex"
from="1"
to="#ArrayLen( ARGUMENTS.MissingMethodArguments )#">
<cfset LOCAL.Arguments &= (
", " &
"ARGUMENTS.MissingMethodArguments[ #LOCAL.ArgumentIndex# ]"
) />
</cfloop>
<cfset LOCAL.Return = Evaluate(
"VARIABLES.Page.#LOCAL.MethodName#( #LOCAL.Arguments# )"
) />
<cfif (
StructKeyExists( LOCAL, "Return" )
AND
(
(
IsSimpleValue( LOCAL.Return ) AND
(LOCAL.Return NEQ "{null}")
)
OR
(NOT IsSimpleValue( LOCAL.Return ))
)
)>
<cfreturn LOCAL.Return />
<cfelse>
<cfreturn THIS />
</cfif>
<cfelse>
<cfthrow
type="ImageWrapper.InvalidMethod"
message="The method you called does not exist."
detail="The method that you called, #UCase( ARGUMENTS.MissingMethodName )#, is not currently supported."
/>
</cfif>
</cffunction>
</cfcomponent>