<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Web 3.0, 6 Bladed Razors, 7 Minute Abs &#187; PHP</title>
	<atom:link href="http://www.zachleat.com/web/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zachleat.com/web</link>
	<description></description>
	<pubDate>Thu, 21 Aug 2008 06:02:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Surnamespacing</title>
		<link>http://www.zachleat.com/web/2008/05/07/surnamespacing/</link>
		<comments>http://www.zachleat.com/web/2008/05/07/surnamespacing/#comments</comments>
		<pubDate>Thu, 08 May 2008 01:30:31 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
		
		<category><![CDATA[Humor]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/?p=133</guid>
		<description><![CDATA[Everyone has a library.  Everyone has their own utility classes and functions they're using in their own personal and contracted projects.  And now that everyone has a blog too, they're all releasing their libraries as open source, using the commando underoo philosophy of wild, free, and unrestricted naming schemes for their code.  Not anymore.  Let's surnamespace.]]></description>
			<content:encoded><![CDATA[<p>Everyone has a library.  Everyone has their own utility classes and functions they're using in their own personal and contracted projects.  And now that everyone has a blog too, they're all releasing their libraries as open source, using the commando underoo philosophy of wild, free, and unrestricted naming schemes for their code.  Not anymore.  Let's surnamespace.</p>
<p>What does surnamespacing give me?</p>
<ul>
<li><strong>Accountability</strong>: Your code is directly linked to your family honor.  You'd be surprised how hard people work at test cases and increased code coverage when the respect of their lineage is at stake.</li>
<li><strong>Connect</strong> with your Extended Family: Connect with programmers sharing your namespace, your family is now your development team.</li>
<li><strong>Minimize Collisons</strong>: The ball and chain associated with an imposed naming scheme means that we won't have everyone using foo and bar to hold their code, unless you're the lucky son of a bitch that has inherited that top notch surnamespace real estate.</li>
<li><strong>Faster</strong> Initial Development Cycle: Sometimes naming your library is the hardest part.  Skip this step and just surnamespace it.</li>
<p>Jesus Christ, please show me some examples:</p>
<p><strong>JavaScript Surnamespacing</strong></p>
<div class="syntax_hilite">
<div id="javascript-1">
<div class="javascript"><span style="color: #003366; font-weight: bold;">var</span> Christ = <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; Jesus: <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; walkOn: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; turn: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>from, to<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; respawn: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span>;<br />
<span style="color: #009900; font-style: italic;">// Sample Usage</span><br />
Christ.<span style="color: #006600;">Jesus</span>.<span style="color: #006600;">walkOn</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'water'</span><span style="color: #66cc66;">&#41;</span>;<br />
Christ.<span style="color: #006600;">Jesus</span>.<span style="color: #006600;">turn</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'water'</span>, <span style="color: #3366CC;">'wine'</span><span style="color: #66cc66;">&#41;</span>;<br />
Christ.<span style="color: #006600;">Jesus</span>.<span style="color: #006600;">respawn</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</div>
</div>
<p></p>
<p><strong>Java Surnamespacing</strong></p>
<div class="syntax_hilite">
<div id="java-2">
<div class="java">package Christ;<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Jesus <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> walkOn<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> s<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> turn<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> from, <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> to<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> respawn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></p>
<p><strong>PHP 6 Surnamespacing (<a href="http://php.net/~derick/meeting-notes.html">projected usage</a>)</strong></p>
<div class="syntax_hilite">
<div id="php-3">
<div class="php">namespace Christ <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#000000; font-weight:bold;">class</span> Jesus <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> walkOn<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$obj</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> turn<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$from</span>, <span style="color:#0000FF;">$to</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; public <span style="color:#000000; font-weight:bold;">function</span> respawn<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</div>
</div>
<p></p>
<p><strong>Update</strong>: Apparently I can't write Java code.  Don't tell work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/2008/05/07/surnamespacing/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP Pretty Date</title>
		<link>http://www.zachleat.com/web/2008/02/10/php-pretty-date/</link>
		<comments>http://www.zachleat.com/web/2008/02/10/php-pretty-date/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 21:13:21 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Dates]]></category>

		<category><![CDATA[Propel]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2008/02/10/php-pretty-date/</guid>
		<description><![CDATA[This class is pretty much a direct port of John Resig's JavaScript Pretty Date to PHP 5.  A few notes:

Requires PHP >= 5.10, due to the usage of PHP's new DateTimeclass.
The new DateTime object parses strings using PHP's strtotime, so you don't need to pass in an ISO8601 formatted date, as in JavaScript Pretty [...]]]></description>
			<content:encoded><![CDATA[<p>This class is pretty much a direct port of <a href="http://ejohn.org/blog/javascript-pretty-date/">John Resig's JavaScript Pretty Date</a> to PHP 5.  A few notes:</p>
<ul>
<li>Requires PHP >= 5.10, due to the usage of PHP's new <a href="http://us3.php.net/manual/en/function.date-create.php">DateTime</a>class.</li>
<li>The new DateTime object parses strings using PHP's <a href="http://us3.php.net/manual/en/function.strtotime.php">strtotime</a>, so you don't need to pass in an ISO8601 formatted date, as in JavaScript Pretty Date. Try "now", or "next Wednesday", or "+2 weeks 4 days 23 hours 9 seconds".</li>
<li>Extended to handle Months and Years in the past (JavaScript version only goes to weeks)</li>
</ul>
<p>Usage:</p>
<div class="syntax_hilite">
<div id="php-5">
<div class="php"><span style="color:#FF9933; font-style:italic;">// pass in a String DateTime, compared to another String DateTime (defaults to now)</span><br />
<span style="color:#0000FF;">$myString</span> = Date_Difference::<span style="color:#006600;">getStringResolved</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'-7 weeks'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#0000FF;">$myString</span> = Date_Difference::<span style="color:#006600;">getStringResolved</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'-7 weeks'</span>, <span style="color:#FF0000;">'+1 week'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</p>
<p><span style="color:#FF9933; font-style:italic;">// pass in a DateTime object, compared to another DateTime object (defaults to now)</span><br />
<span style="color:#FF9933; font-style:italic;">// useful with the Propel ORM, which uses DateTime objects internally.</span><br />
<span style="color:#0000FF;">$myString</span> = Date_Difference::<span style="color:#006600;">getString</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">new</span> DateTime<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'-7 weeks'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<span style="color:#0000FF;">$myString</span> = Date_Difference::<span style="color:#006600;">getString</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">new</span> DateTime<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'-7 weeks'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#000000; font-weight:bold;">new</span> DateTime<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'+1 week'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</div>
</div>
<p></p>
<p><a href="http://www.zachleat.com/Projects/phpPrettyDate/Date_Difference.phps">Download PHP Pretty Date</a> (PHP 5.10+, 1.86KB)<br />
<a href="http://www.zachleat.com/Projects/phpPrettyDate/Date_Difference.phps">http://www.zachleat.com/Projects/phpPrettyDate/Date_Difference.phps</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/2008/02/10/php-pretty-date/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Nursery Rhyme Code Poem [PHP]</title>
		<link>http://www.zachleat.com/web/2007/10/26/nursery-rhyme-design-patterns-php/</link>
		<comments>http://www.zachleat.com/web/2007/10/26/nursery-rhyme-design-patterns-php/#comments</comments>
		<pubDate>Sat, 27 Oct 2007 01:54:14 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
		
		<category><![CDATA[Artistic]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Code Poem]]></category>

		<category><![CDATA[Nursery Rhymes]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/10/26/nursery-rhyme-design-patterns-php/</guid>
		<description><![CDATA[

&#60;?php
class I &#123;
&#160; &#160; public __construct&#40;&#41;
&#160; &#160; &#123;
&#160; &#160; &#160; &#160; $star = new Star&#40;&#41;;
&#160; &#160; &#160; &#160; $star-&#62;size = 'little';
&#160; &#160; &#160; &#160; $star-&#62;twinkle&#40;&#41;;
&#160; &#160; &#160; &#160; $star-&#62;twinkle&#40;&#41;;
&#160; &#160; &#160; &#160; self::wonder&#40;$star, 'What are you?'&#41;;
&#160; &#160; &#160; &#160; $world = new World&#40;&#41;;
&#160; &#160; &#160; &#160; $world-&#62;elevation = 'So High';
&#160; &#160; &#160; &#160; $star-&#62;setAbove&#40;$world&#41;;
&#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<div class="syntax_hilite">
<div id="php-7">
<div class="php"><span style="color:#000000; font-weight:bold;">&lt;?php</span><br />
<span style="color:#000000; font-weight:bold;">class</span> I <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; public __construct<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$star</span> = <span style="color:#000000; font-weight:bold;">new</span> Star<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$star</span>-&gt;<span style="color:#006600;">size</span> = <span style="color:#FF0000;">'little'</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$star</span>-&gt;<span style="color:#006600;">twinkle</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$star</span>-&gt;<span style="color:#006600;">twinkle</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; self::<span style="color:#006600;">wonder</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$star</span>, <span style="color:#FF0000;">'What are you?'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$world</span> = <span style="color:#000000; font-weight:bold;">new</span> World<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$world</span>-&gt;<span style="color:#006600;">elevation</span> = <span style="color:#FF0000;">'So High'</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$star</span>-&gt;<span style="color:#006600;">setAbove</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$world</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$d</span> = <span style="color:#000000; font-weight:bold;">new</span> Diamond<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$d</span>-&gt;<span style="color:#006600;">position</span> = <span style="color:#FF0000;">'In the sky'</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$star</span>-&gt;<span style="color:#006600;">setLike</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$d</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$star</span>-&gt;<span style="color:#006600;">twinkle</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$star</span>-&gt;<span style="color:#006600;">twinkle</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$star</span>-&gt;<span style="color:#006600;">size</span>; <span style="color:#FF9933; font-style:italic;">// returns 'little'</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; self::<span style="color:#006600;">wonder</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$star</span>, <span style="color:#FF0000;">'What are you?'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></p>
<p>&nbsp; &nbsp; public <a href="http://www.php.net/static"><span style="color:#000066;">static</span></a> <span style="color:#000000; font-weight:bold;">function</span> wonder<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$obj</span>, <span style="color:#0000FF;">$query</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$obj</span>-&gt;<span style="color:#006600;">query</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$query</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</div>
</div>
<p></p>
<p><em>The above <strong>code poem</strong> is released under the BSD license.</em>  To use in production environment without error, please precede with the following command: <code>error_reporting(0);</code>  Obviously I'm kidding, don't use this code.  Not even for enterprise software.</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/poem" rel="tag"> poem</a>, <a href="http://technorati.com/tag/code+poem" rel="tag"> code poem</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/2007/10/26/nursery-rhyme-design-patterns-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Phing to automate JavaScript and CSS Minimization</title>
		<link>http://www.zachleat.com/web/2007/08/11/using-phing-to-automate-javascript-and-css-minimization/</link>
		<comments>http://www.zachleat.com/web/2007/08/11/using-phing-to-automate-javascript-and-css-minimization/#comments</comments>
		<pubDate>Sat, 11 Aug 2007 06:33:53 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[csstidy]]></category>

		<category><![CDATA[Packer]]></category>

		<category><![CDATA[Phing]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/08/11/using-phing-to-automate-javascript-and-css-minimization/</guid>
		<description><![CDATA[This article may be too advanced for beginner programmers.  Unfortunately, I will not support any code that I do not write (in this case), so if you have troubles installing some of the packages required below, please see the authors of the problem code.  Thank you.
PHING!  Party on Wayne.  Party on [...]]]></description>
			<content:encoded><![CDATA[<p><em>This article may be too advanced for beginner programmers.  Unfortunately, I will not support any code that I do not write (in this case), so if you have troubles installing some of the packages required below, please see the authors of the problem code.  Thank you.</em></p>
<p>PHING!  <a href="http://en.wikipedia.org/wiki/Wayne%27s_World">Party on Wayne.  Party on Garth!</a></p>
<p>If you've never used Phing, it's an automation tool for PHP that is a port of Java's ANT Build tool.  But it's not just for building (obviously, that'd be silly).  You can hook all kinds of tasks into Phing: unit tests for your PHP code (you're doing test driven development, aren't you?), building your documentation, etc.  But today, let's look at automation of my favorite front end development tasks: packing (minimizing) our JavaScript and CSS.</p>
<p>To do this, I'm going to hook you up with two Filters for Phing that will use the <a href="http://joliclic.free.fr/php/javascript-packer/en/">PHP port of Dean Edwards JavaScript Packer</a>, and the PHP class <a href="http://csstidy.sourceforge.net/">CSSTidy</a>.</p>
<p>Here's what you'll be responsible for:</p>
<ol>
<li>Download both CSSTidy and the PHP port of Packer using the links above.</li>
<li>Download Phing if you don't already have it, and install it.  Note the following change I had to make to my Phing \bin\phing.bat file to get it working: Change <code>set PHP_CLASSPATH="%PHING_HOME%\classes"</code> to remove the quotes: <code>set PHP_CLASSPATH=%PHING_HOME%\classes</code></li>
<li>Download the two Filters I made for Phing: <strong><a href="/Projects/phing/JSPackerFilter.phps">JSPackerFilter.phps</a></strong> and <strong><a href="/Projects/phing/CssTidyFilter.phps">CssTidyFilter.phps</a></strong>, change the extensions to .php and copy into your phing directory \classes\phing\filters\</li>
<li>Change the path in the include_once declaration at the top of each of the files to point to the csstidy and packer libraries you downloaded above:
<div class="syntax_hilite">
<div id="php-13">
<div class="php"><span style="color:#616100;">include_once</span> <span style="color:#FF0000;">"C:<span style="color:#000099; font-weight:bold;">\L</span>ib<span style="color:#000099; font-weight:bold;">\p</span>acker.php-1.0<span style="color:#000099; font-weight:bold;">\c</span>lass.JavaScriptPacker.php"</span>;</div>
</div>
</div>
<p></p>
<div class="syntax_hilite">
<div id="php-14">
<div class="php"><span style="color:#616100;">include_once</span> <span style="color:#FF0000;">"C:<span style="color:#000099; font-weight:bold;">\L</span>ib<span style="color:#000099; font-weight:bold;">\c</span>sstidy-1.3<span style="color:#000099; font-weight:bold;">\c</span>lass.csstidy.php"</span>;</div>
</div>
</div>
<p>
</li>
<li>Get a working build file set up to point the directories your project is using.  Here is a sample I made:
<div class="syntax_hilite">
<div id="xml-15">
<div class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span>?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">"1.0"</span>?<span style="font-weight: bold; color: black;">&gt;</span></span><br />
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"testProject"</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">"pack-all"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"pack-all"</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">"pack-javascript,pack-css"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"pack-javascript"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">"./Web/js"</span> <span style="color: #000066;">overwrite</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">"../Web/js"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"*.js"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/fileset<span style="font-weight: bold; color: black;">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filterchain<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filterreader</span> <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">"phing.filters.JSPackerFilter"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"encoding"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"62"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- 0,10,62,95 or 'None', 'Numeric', 'Normal', 'High ASCII'. --&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"fastDecode"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- include the fast decoder in the packed result --&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"specialCharacters"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"false"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- have you flagged your private and local variables in the script --&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filterreader<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filterchain<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/copy<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/target<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"pack-css"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">"./Web/css"</span> <span style="color: #000066;">overwrite</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">"../Web/css"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"*.css"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/fileset<span style="font-weight: bold; color: black;">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filterchain<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filterreader</span> <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">"phing.filters.CssTidyFilter"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"remove_last_;"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"preserveCss"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"false"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"template"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"high_compression"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filterreader<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filterchain<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/copy<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/target<span style="font-weight: bold; color: black;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/project<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</div>
</div>
<p></p>
<p>Templates for CssTidy include: low_compression, default, high_compression (declarations are limited to one line apiece), highest_compression (everything is put on one line).</p>
<p>The above build file is set up to work with the following directory structure:</p>
<ul>
<li>Build
<ul>
<li>Web
<ul>
<li>css</li>
<li>js</li>
</ul>
</li>
<li><strong>build.xml</strong></li>
</ul>
</li>
<li>Web
<ul>
<li>css</li>
<li>js</li>
</ul>
</li>
</ul>
<p>Files are copied from the source in /Web to the /Build/Web directory.  I hope that you can see from the build.xml file above that the target directory is specified in the copy tag, todir attribute.</p>
<div class="syntax_hilite">
<div id="xml-16">
<div class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">"./Web/js"</span> <span style="color: #000066;">overwrite</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</div>
</div>
<p></p>
<p>and the source directory is specified in the fileset tag, dir attribute.</p>
<div class="syntax_hilite">
<div id="xml-17">
<div class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">"../Web/css"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"*.css"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/fileset<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</div>
</div>
<p>
</copy></li>
</ol>
<p>And then, all you need to do is navigate to the directory holding your build.xml and run the phing command (if you have phing in your path. If not, you can use an absolute link to phing, for example c:\software\phing\bin\phing).  Your minimized javascript and css will be in the Build directory!</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/Phing" rel="tag">Phing</a>, <a href="http://technorati.com/tag/Packer" rel="tag"> Packer</a>, <a href="http://technorati.com/tag/csstidy" rel="tag"> csstidy</a>, <a href="http://technorati.com/tag/JavaScript" rel="tag"> JavaScript</a>, <a href="http://technorati.com/tag/CSS" rel="tag"> CSS</a>, <a href="http://technorati.com/tag/PHP" rel="tag"> PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/2007/08/11/using-phing-to-automate-javascript-and-css-minimization/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
