Categorized | News, OOP

Modularising Workflow with an Intercepting Filter

Posted on 30 September 2005 by Demian Turner

While we’re on the subject of useful refactorings, I’d like to describe how using an Intercepting Filter helped round up and modularise software setup and initialisation tasks. Before the code could get down to business with the framework’s main task, the SGL_MainProcess, (eg booking a hotel room or editing an FAQ, whatever), a certain amount of setup was necessary.

In the previous version, a number of initialisation tasks were assigned to a single init() method in the AppController, then executed procedurally. The disadvantage of this approach was that the tasks were not testable, they were difficult to reorder, and it was prohibitive to insert custom routines into the pipeline.

Enter the Intercepting Filter, which is basically a chain of decorators. The idea is that you have your main process, then you decorate it with n filters or tasks required to get your system correctly initialised beforehand. The code makes the example clearer:

class SGL_AppController
function run()
$input = &SGL_RequestRegistry::singleton();
$input->setRequest($req = SGL_Request::singleton());

$process = new SGL_Init(
new SGL_DiscoverClientOs(
new SGL_ManagerResolver(
new SGL_InitSession(
new SGL_InitLangSupport(
new SGL_InitPerms(
new SGL_AuthenticateRequest(
new SGL_BuildHeaders(
new SGL_SetLocale(
new SGL_DetectDebug(
new SGL_DetectBlackListing(
new SGL_MainProcess()


From Matt Zandstra’s book:

The model is very extensible. We can add new decorators and components very easily. With lots of decorators we can build very flexible structures at runtime. The component class [in our case SGL_MainProcess] can be significantly modified in very many ways without the need to build the totality of the modifications into the class hierarchy.

Here’s the UML:

Bookmark and Share

1 Comments For This Post

  1. PHP kitchen Says:

    Like many projects, we’re running two streams of releases, stable and devel. The development release includes the test runner and all unit and web tests, as well as developer docs which include Poseidon UML diagrams, etc. It’s recommended for folks w

Leave a Reply



Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists



PHPkitchen recommends you also check out the following sites :

Accounting for Small Businesses

FreeAgent sign-up