Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 24, 2014 23:34
Show Gist options
  • Save bennadel/9751699 to your computer and use it in GitHub Desktop.
Save bennadel/9751699 to your computer and use it in GitHub Desktop.
My ColdFusion User Defined Function Library Structure
REQUEST.UDFLib = APPLICATION.ServiceFactory.GetUDFLib();
<cfset APPLICATION.UDFLib = CreateObject( "component", "UDFLib" ).Init() />
<cfcomponent
displayname="UDFLib"
extends="AbstractBaseComponent"
output="no"
hint="Houses all the user defined functions for this application.">
<cffunction name="Init" access="public" returntype="UDFLib" output="no"
hint="Returns an initialized user defined library instance.">
<cfscript>
// Since this is a library and NOT a real entity bean, we are going to
// store all library references in the THIS scope so that they are
// easily accessible to anyone who has an instance reference.
// System contains core system functions.
THIS.System = CreateObject( "component", "UDFlib.SystemLib" ).Init( THIS );
// AJAX contains AJAX utility functions.
THIS.AJAX = CreateObject( "component", "UDFLib.AJAXLib" ).Init( THIS );
// Array contains array manipulation functions.
THIS.Array = CreateObject( "component", "UDFLib.ArrayLib" ).Init( THIS );
// DateTime contains date and time manipulation functions.
THIS.DateTime = CreateObject( "component", "UDFlib.DateTimeLib" ).Init( THIS );
// List contains list manipulation functions.
THIS.List = CreateObject( "component", "UDFlib.ListLib" ).Init( THIS );
// IO contains input and output related functions.
THIS.IO = CreateObject( "component", "UDFlib.IOLib" ).Init( THIS );
// Query contains query manipulation functions.
THIS.Query = CreateObject( "component", "UDFlib.QueryLib" ).Init( THIS );
// Struct contains struct manipulation functions.
THIS.Struct = CreateObject( "component", "UDFlib.StructLib" ).Init( THIS );
// Text contains text manipulation functions.
THIS.Text = CreateObject( "component", "UDFlib.TextLib" ).Init( THIS );
// Validation contains data validation functions.
THIS.Validation = CreateObject( "component", "UDFlib.ValidationLib" ).Init( THIS );
// Xml contains xml manipulation functions.
THIS.Xml = CreateObject( "component", "UDFlib.XmlLib" ).Init( THIS );
// The custom library is stuff that is decidedly NOT part of the main function
// library as it has been created specifically for the current application. This
// library would not be used for a different application.
THIS.Custom = CreateObject( "component", "UDFlib.CustomLib" ).Init( THIS );
// Return THIS object.
return( THIS );
</cfscript>
</cffunction>
</cfcomponent>
<cfset qNew = UDFLib.Query.Append( qOne, qTwo ) />
<cffunction
name="Init"
access="public"
returntype="ArrayLib"
output="no"
hint="Returns an initialized library instance.">
<!--- Define arguments. --->
<cfargument name="Library" type="struct" required="yes" />
<cfscript>
// The library variable is a reference to the main UDF
// library. This is going to be used to reference other
// parts of the library that are not in this specific
// component.
VARIABLES.Library = ARGUMENTS.Library;
// Return THIS object.
return(THIS);
</cfscript>
</cffunction>
<cfset strText = VARIABLES.Library.Text.ToAsciiString( "-" ) />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment