In addition to all the events announced by the framework, you can also register your own custom events.
Curt Gratz shares a brief example and use case for ColdBox custom interception points in his video ColdBox Custom Interception Points - How To.
You can use the interceptor service to register new events or interception points via the appendInterceptionPoints()
method. This way you can dynamically register events in your system:
The value of the customPoints
argument can be a list or an array of interception points to register so the interceptor service can manage them for you:
In the ColdBox.cfc
configuration file, there is a structure called interceptorSettings
with two keys:
throwOnInvalidStates
- This tells the interceptor service to throw an exception if the state announced for interception is not valid or does not exist. By default it does not throw an exception but ignore the announcement.
customInterceptionPoints
- This key is a comma delimited list of custom interception points you will be registering for execution.
The customInterceptionPoints
is what interest us. This can be a list or an array of events your system can broadcast. This way, whenever interceptors are registered, they will be inspected for those events.
The last piece of the puzzle is how to announce events. You will do so via the inherited super type method announceInterception()
that all your handlers,plugins and even the interceptors themselves have or via the interceptor service processState()
method. This method accepts an incoming data struct which will be broadcasted alongside your event:
Hint Announcing events can also get some asynchronous love, read the Interceptor Asynchronicity for some asynchronous love.
Once your custom interception or event points are registered and CFC are registered then you can write the methods for listening to those events just like any other interceptor event: