Automatic indexing of CB event handlers

Just wanted to share some code that will loop all the registered event handlers of a ColdBox application. This function is called every time a fwreinit is received and pass all the events to my security model so they can be configured for authentication.

	private void function generateAllPossibleNonExistentRules() event=false {
		var configStruct = getSettingsBean().getConfigStruct();
		var HandlersInvocationPath = configStruct.HandlersInvocationPath;
		var RegisteredHandlers = configStruct.RegisteredHandlers;

		var HandlerEvents = {};
		for(var i = 1; i<=ListLen(RegisteredHandlers);i++) {
			var thisHandler = listGetAt(RegisteredHandlers,i);
			var thisHandlerPath = HandlersInvocationPath & '.' & thisHandler;
			var md = GetComponentMetaData( thisHandlerPath );
			var eventsArray = [];
			if(ArrayLen(md.functions)) {
				for(var y = 1; y <= ArrayLen(md.functions);y++) {
					var func = md.functions[y];
					// This is important, just grab everything not marked with event=false on the function
					if(!StructKeyExists(func,'event')) {
			if(ArrayLen(eventsArray)) {
				HandlerEvents[thisHandler] = eventsArray;

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

WordPress Appliance - Powered by TurnKey Linux