Created
November 10, 2015 08:52
-
-
Save elpete/835ad0f7d017439db871 to your computer and use it in GitHub Desktop.
Pull Request proposal for adding WireBox listeners on the fly (like in Modules)
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
<!--- listener ---> | |
<cffunction name="listener" output="false" access="public" returntype="any" hint="Add a new listener configuration."> | |
<cfargument name="class" required="true" hint="The class of the listener"/> | |
<cfargument name="properties" required="false" default="#structNew()#" hint="The structure of properties for the listner" colddoc:generic="Struct"/> | |
<cfargument name="name" required="false" default="" hint="The name of the listener"/> | |
<cfargument name="registerWithInjector" required="false" default="false" hint="Register the listener with the injector"/> | |
<cfscript> | |
// Name check? | |
if( NOT len(arguments.name) ){ | |
arguments.name = listLast(arguments.class,"."); | |
} | |
// add listener | |
arrayAppend(instance.listeners, arguments); | |
if (arguments.registerWithInjector) { | |
instance.injector.registerListener(arguments); | |
} | |
return this; | |
</cfscript> | |
</cffunction> |
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
<!--- registerListeners ---> | |
<cffunction name="registerListeners" output="false" access="private" returntype="void" hint="Register all the configured listeners in the configuration file"> | |
<cfscript> | |
var listeners = instance.binder.getListeners(); | |
var regLen = arrayLen(listeners); | |
var x = 1; | |
var thisListener = ""; | |
// iterate and register listeners | |
for(x=1; x lte regLen; x++){ | |
registerListener(listeners[x]) | |
} | |
</cfscript> | |
</cffunction> | |
<!--- registerListeners ---> | |
<cffunction name="registerListener" output="false" access="public" returntype="void" hint="Register a single listener"> | |
<cfargument name="listener" type="struct" required="true"> | |
<cfscript> | |
try{ | |
// create it | |
thisListener = createObject("component", arguments.listener.class); | |
// configure it | |
thisListener.configure( this, arguments.listener.properties); | |
} | |
catch(Any e){ | |
instance.log.error("Error creating listener: #arguments.listener.toString()#", e); | |
throw(message="Error creating listener: #arguments.listener.toString()#", | |
detail="#e.message# #e.detail# #e.stackTrace#", | |
type="Injector.ListenerCreationException"); | |
} | |
// Now register listener | |
if( NOT isColdBoxLinked() ){ | |
instance.eventManager.register(thisListener,arguments.listener.name); | |
} | |
else{ | |
instance.eventManager.registerInterceptor(interceptorObject=thisListener,interceptorName=arguments.listener.name); | |
} | |
// debugging | |
if( instance.log.canDebug() ){ | |
instance.log.debug("Injector has just registered a new listener: #arguments.listener.toString()#"); | |
} | |
</cfscript> | |
</cffunction> |
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
binder.listener(class = 'coldbox.system.aop.Mixer', registerWithInjector = true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment