Convention over Configuration - ColdBox Series Part 5
In my next post, I promise we will get back to coding. But first, I just wanted to make a quick post about "Convention over Configuration" with the ColdBox Framework.
Last time I checked, this was unique to ColdBox, this may have changed for FuseBox though, but ColdBox does not use an XML file to define event handlers, plugins, interceptors, views or anything other than where the framework should look for these things. It is all done through conventions (or standards).
Handlers are stored in a specific place (the /handlers directory). Any CFC found in there that extends coldbox.system.eventhandler is examined for public methods, and any public methods found are automatically registered with the framework as an event handler.
The same is true for Plugins, Interceptors, Layouts and Views. Therefore, there is no need for the XML config file to define each of these items. The framework already knows where and how to find them.
Additionally, you can change the conventions if you like, by modifying the coldbox.xml file that we talked about yesterday.
So if you wanted to change the location of your handlers directory from /handlers to /myhandlers you could do it in lines 127-132 (approx) of the coldbox.xml file.
<!-- Custom Conventions : You can override the framework wide conventions of the locations of the needed objects -->
<Conventions>
<handlersLocation>myhandlers</handlersLocation>
<!-- <pluginsLocation></pluginsLocation> -->
<!-- <layoutsLocation></layoutsLocation> -->
<!-- <viewsLocation></viewsLocation> -->
<!-- <eventAction></eventAction> -->
</Conventions>
And you could do the same for plugins, layouts, views and event actions (whatever those are) simply by uncommenting the tags and entering the path you would like.






I welcome any comments that point out similarities between this and the functionality of Fusebox.
The onTap framework has always been a CoC-style framework. The latest version uses a config.cfc which is more like Application.cfc (as opposed to an XML file). And although it doesn't include declarations for directories like this, you could make those kinds of modifications if you wanted to by overriding the methods it inherits from tap.cfc. For that matter you could basically rewrite the entire framework if you had some compelling reason to simply by modifying your config.cfc to support whatever it is you need.