Created
June 25, 2022 18:02
-
-
Save bennadel/70893a691e5b35d00c55c3a5155177e9 to your computer and use it in GitHub Desktop.
Namespacing Components With Per-Application Mappings In ColdFusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component | |
output = false | |
hint = "I define the application settings and event handlers." | |
{ | |
// Define the application settings. | |
this.name = "CompoundPathMappingTest"; | |
this.applicationTimeout = createTimeSpan( 0, 1, 0, 0 ); | |
// When referencing ColdFusion components, paths are delimited with "." instead of | |
// with "/". However, those paths ultimately map to folder structures. As such, if we | |
// want to create a "namespace" (so to speak) for a set of components, we have to | |
// create a ColdFusion mapping that lays-out the virtual file-based paths for our | |
// namespace. | |
// -- | |
// CAUTION: The mapping keys cannot end in a slash - this will break Adobe ColdFusion. | |
// But, appears to work fine in Lucee CFML. | |
this.mappings = { | |
"/com/bennadel/kablamo": getDirectoryFromPath( getCurrentTemplatePath() ) | |
}; | |
// --- | |
// PUBLIC METHODS. | |
// --- | |
/** | |
* I handle the execution of the requested script. | |
*/ | |
public void function onRequest() { | |
// Our namespace - "com.bennadel.kablamo" - is using the "/com/bennadel/kablamo" | |
// per-application custom mapping. | |
var self = new com.bennadel.kablamo.lib.SubClass() | |
.getSelf() | |
; | |
writeDump( | |
label = "Compound Path Mapping Test", | |
var = self | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* NOTE: Using the namespace in "extends". | |
*/ | |
component | |
extends = "com.bennadel.kablamo.lib.BaseClass" | |
{ | |
this.isSubClass = true; | |
/** | |
* NOTE: Using the namespace in the return type signature. | |
*/ | |
public com.bennadel.kablamo.lib.SubClass function getSelf() { | |
return( this ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment