By convention, any interceptor CFC must create a method with the same name as the event they want to listen to. This method has a return type of boolean
and receives 3 arguments. So let's explore their rules.
event
which is the request context object
interceptData
which is a structure of data that the broadcaster sends
buffer
which is a request buffer object you can use to elegantly produce content that is outputted to the user's screen
rc
reference to the request collection struct
prc
reference to the private request collection struct
The intercepting method returns boolean
or void
. If boolean then it means something:
True means break the chain of execution, so no other interceptors in the chain will fire.
False or void
continue execution
Also remember that all interceptors are created by WireBox, so you can use dependency injection, configuration binder's, and even AOP on interceptor objects. Here is a more complex sample:
HTTP Security Example:
Interceptors are CFCs that extend the ColdBox Interceptor class (coldbox.system.Interceptor
), implement a configuration method called configure()
, and then contain methods for the events it will listen for. All interceptors are treated as singletons in your application, so make sure they are thread safe and var scoped.
Info You can also remove the inheritance from the CFC (preferred method) and WireBox will extend the
coldbox.system.Interceptor
for you using Virtual Inheritance.
You can use CommandBox to create interceptors as well:
Interceptors can be registered in your Coldbox.cfc
configuration file using the interceptors
struct, or they can be registered manually via the system's interceptor service.
In ColdBox.cfc
:
Registered manually:
configure()
MethodThe interceptor has one important method that you can use for configuration called configure()
. This method will be called right after the interceptor gets created and injected with your interceptor properties.
Info These properties are local to the interceptor only!
As you can see on the diagram, the interceptor class is part of the ColdBox framework super type family, and thus inheriting the functionality of the framework.