<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: A simple Filter Chain example in PHP 5</title>
	<link>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5</link>
	<description>Chris Corbyn, WebGeek</description>
	<pubDate>Thu, 28 Aug 2008 23:57:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2</generator>

	<item>
		<title>By: Matthijs</title>
		<link>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5#comment-10262</link>
		<author>Matthijs</author>
		<pubDate>Sat, 12 Apr 2008 07:12:38 +0000</pubDate>
		<guid>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5#comment-10262</guid>
		<description>Wow, that's a pretty cool piece of code. And excellent write-down, thanks. Makes me want to use this somewhere immediately.</description>
		<content:encoded><![CDATA[<p>Wow, that&#8217;s a pretty cool piece of code. And excellent write-down, thanks. Makes me want to use this somewhere immediately.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chris</title>
		<link>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5#comment-1181</link>
		<author>chris</author>
		<pubDate>Sat, 08 Sep 2007 09:02:09 +0000</pubDate>
		<guid>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5#comment-1181</guid>
		<description>I should point out also that this particluar example is run-once, because it uses array_shift which actually reduces the array size as it goes.  If you need to repeatedly run the same filter chain you'd have to use iteration with a little extra logic.</description>
		<content:encoded><![CDATA[<p>I should point out also that this particluar example is run-once, because it uses array_shift which actually reduces the array size as it goes.  If you need to repeatedly run the same filter chain you&#8217;d have to use iteration with a little extra logic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chris</title>
		<link>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5#comment-1180</link>
		<author>chris</author>
		<pubDate>Sat, 08 Sep 2007 08:57:52 +0000</pubDate>
		<guid>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5#comment-1180</guid>
		<description>Yes, sure :)

Back to my FrontController example.  You may want to switch from using the unclean form &lt;em&gt;index.php?module=aModule&#038;action=myAction&lt;/em&gt; in the URL, to parsing out something like &lt;em&gt;index.php/aModule/myAction&lt;/em&gt; and populating the request with the appropriate values.

For the FrontController to work without any prior knowledge of this aesthetic modification you need to ensure the request has been modified as early as possibe.  The best way to do this is the place your request mapping logic in a filter chain which runs before the FrontController is ever reached.

Imagine I change the FilterChain to allow something to explictly run at the end of the chain (I'll pass it to the constructor here).

[code lang="php"]$chain = new FilterChain(new FrontController());
$chain-&gt;addFilter(new RequestMapper());
$chain-&gt;doFilter(new Request(), new Response());[/code]

Now our RequestMapper class can read the REQUEST_URI value and determine what parameters to put in the request.

This is a typical use of the filter chain pattern and one you'll see in some PHP frameworks (and in J2EE as standard).

Ideally you'd have a configuration file which allows filters to be specified loosely :)</description>
		<content:encoded><![CDATA[<p>Yes, sure :)</p>
<p>Back to my FrontController example.  You may want to switch from using the unclean form <em>index.php?module=aModule&#038;action=myAction</em> in the URL, to parsing out something like <em>index.php/aModule/myAction</em> and populating the request with the appropriate values.</p>
<p>For the FrontController to work without any prior knowledge of this aesthetic modification you need to ensure the request has been modified as early as possibe.  The best way to do this is the place your request mapping logic in a filter chain which runs before the FrontController is ever reached.</p>
<p>Imagine I change the FilterChain to allow something to explictly run at the end of the chain (I&#8217;ll pass it to the constructor here).</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="re0">$chain</span> = <span class="kw2">new</span> FilterChain<span class="br0">&#40;</span><span class="kw2">new</span> FrontController<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="re0">$chain</span>-&gt;<span class="me1">addFilter</span><span class="br0">&#40;</span><span class="kw2">new</span> RequestMapper<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="re0">$chain</span>-&gt;<span class="me1">doFilter</span><span class="br0">&#40;</span><span class="kw2">new</span> Request<span class="br0">&#40;</span><span class="br0">&#41;</span>, <span class="kw2">new</span> Response<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</div>
<p>Now our RequestMapper class can read the REQUEST_URI value and determine what parameters to put in the request.</p>
<p>This is a typical use of the filter chain pattern and one you&#8217;ll see in some PHP frameworks (and in J2EE as standard).</p>
<p>Ideally you&#8217;d have a configuration file which allows filters to be specified loosely :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeffery Fernandez</title>
		<link>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5#comment-1177</link>
		<author>Jeffery Fernandez</author>
		<pubDate>Sat, 08 Sep 2007 06:15:23 +0000</pubDate>
		<guid>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5#comment-1177</guid>
		<description>Hey Chris,

Just wondering what real world example can this pattern be used in? Can you suggest some? Thanks</description>
		<content:encoded><![CDATA[<p>Hey Chris,</p>
<p>Just wondering what real world example can this pattern be used in? Can you suggest some? Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bramus!</title>
		<link>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5#comment-795</link>
		<author>Bramus!</author>
		<pubDate>Mon, 20 Aug 2007 08:28:30 +0000</pubDate>
		<guid>http://www.w3style.co.uk/a-simple-filter-chain-example-in-php-5#comment-795</guid>
		<description>Yet again an awesome article Chris! Thanks!</description>
		<content:encoded><![CDATA[<p>Yet again an awesome article Chris! Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
