
Originally Posted by
Selkirk
One thing, though. I would hate to see filter classes being included and instantiated, but never called. Seems like a waste.
Good point (again)! Here's a modification to FilterChain:
PHP Code:
class FilterChain
{
var $filters = array();
function FilterChain()
{
}
function register($filterClass)
{
$this->filters[] = $filterClass;
}
function execute()
{
reset($this->filters);
$this->next();
}
function next()
{
if ($filterClass = current($this->filters))
{
next($this->filters);
include_once('filters/' . $filterClass . '.class.php');
$filter =& new $fcfilterClass);
$filter->run($this);
}
}
}
This would change frontcontroller.inc.php to:
PHP Code:
require_once('FilterChain.class.php');
$fc =& new FilterChain();
$fc->register('OutputBufferingFilter');
$fc->register('TimingFilter');
$fc->register('RequestDispatchingFilter');
$fc->execute();
exit;
There are two obvious problems though:
1. I'm making assumptions about the location and naming of the filters.
2. There's no way to pass parameters to the Filter constructors.
Any suggestions? As always, I want to keep things as absolutely simple as possible.
Bookmarks