<cfcomponent
output="false"
hint="Creates, intializes, and wires together all objects that are needed in the system.">
<cfset VARIABLES.Instance = {} />
<cffunction
name="Init"
access="public"
returntype="any"
output="false"
hint="Returns an initialized component.">
<cfargument
name="Config"
type="any"
required="true"
hint="The application configuration object."
/>
<cfset VARIABLES.Instance.Config = ARGUMENTS.Config />
<cfset VARIABLES.Instance.UDF = THIS.CreateCFC( "UDF" ).Init() />
<cfset VARIABLES.Instance.PhotoGalleryService = THIS.CreateCFC( "PhotoGalleryService" ) />
<cfset VARIABLES.Instance.PhotoService = THIS.CreateCFC( "PhotoService" ) />
<cfset VARIABLES.Instance.CommentService = THIS.CreateCFC( "CommentService" ) />
<cfset VARIABLES.Instance.PhotoGalleryService.InjectDependency(
"DSN",
THIS.Get( "Config" ).DSN
).Init() />
<cfset VARIABLES.Instance.PhotoService.InjectDependency(
"DSN",
THIS.Get( "Config" ).DSN
).Init() />
<cfset VARIABLES.Instance.CommentService.InjectDependency(
"DSN",
THIS.Get( "Config" ).DSN
).Init() />
<cfreturn THIS />
</cffunction>
<cffunction
name="CreateCFC"
access="public"
returntype="any"
output="false"
hint="Returns the given CFC.">
<cfargument
name="CFC"
type="string"
required="true"
hint="The relative path to the CFC to create."
/>
<cfreturn CreateObject( "component", ARGUMENTS.CFC ) />
</cffunction>
<cffunction
name="Get"
access="public"
returntype="any"
output="false"
hint="Returns the given object.">
<cfargument
name="Type"
type="string"
required="true"
hint="The type of object that we need to return."
/>
<cfif StructKeyExists( VARIABLES.Instance, ARGUMENTS.Type )>
<cfreturn VARIABLES.Instance[ ARGUMENTS.Type ] />
<cfelseif (ARGUMENTS.Type EQ "ErrorCollection")>
<cfreturn THIS.CreateCFC( ARGUMENTS.Type ).Init() />
<cfelse>
<cfthrow
type="OOPhoto.UnknownObjectType"
message="You have requested an unknown object type."
detail="The object type you have requested #UCase( ARGUMENTS.Type )# is not valid for this object factory."
/>
</cfif>
</cffunction>
</cfcomponent>