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')) { ArrayAppend(eventsArray,func.name); } } } if(ArrayLen(eventsArray)) { HandlerEvents[thisHandler] = eventsArray; } } securityRuleService.importFromOnAppInit(HandlerEvents); }
0 Comments.