<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Aaron Saray » Blog</title>
	
	<link>http://aaronsaray.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Tue, 31 Jan 2012 16:12:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/aaronsaray" /><feedburner:info uri="aaronsaray" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><image><link>http://aaronsaray.com</link><url>http://assets.aaronsaray.com/images/logo.png</url><title>Aaron Saray</title></image><feedburner:emailServiceId>aaronsaray</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Creating a custom Zend Framework Body Script helper</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/q4cBZJAHIvc/</link>
		<comments>http://aaronsaray.com/blog/2012/01/31/creating-a-custom-zend-framework-body-script-helper/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 16:12:11 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/?p=1008</guid>
		<description><![CDATA[It drives me nuts that the best practices with javascript that is not required for the initial rendering of your application is to be placed at the bottom of the document, yet frameworks (like Zend Framework) do not support that &#8230; <a href="http://aaronsaray.com/blog/2012/01/31/creating-a-custom-zend-framework-body-script-helper/">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://aaronsaray.com/blog/2012/01/31/creating-a-custom-zend-framework-body-script-helper/">Creating a custom Zend Framework Body Script helper</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>It drives me nuts that the best practices with javascript that is not required for the initial rendering of your application is to be placed at the bottom of the document, yet frameworks (like Zend Framework) do not support that out of the box.  (I recently found out that Joomla also shares this problem.) </p>
<p>By default, in Zend Framework, the Zend View Helper of HeadScript allows additions to the header of the document (now, technically you could just call the headScript() output in the body of your layout, and this would fix it, but that&#8217;s not very semantic, is it?).</p>
<p>I&#8217;ve created my own solution.  Now, I put headScript() items only in the head when necessary, and I add everything else to my new custom bodyScript() handler.  This is simply extending the headScript() handler for a different position.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1008code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10083"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p1008code3"><div class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Application_View_Helper_BodyScript <span style="color: #000000; font-weight: bold;">extends</span> Zend_View_Helper_HeadScript<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* @var string The key to store this in the registry<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_regKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Application_View_Helper_BodyScript'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Proxy for the different named head script<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> bodyScript<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/func_get_args"><span style="color: #990000;">func_get_args</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/call_user_func_array"><span style="color: #990000;">call_user_func_array</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'headScript'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></table></div>

<p>You&#8217;ll notice it simply is simply extending the headScript item and calling it the bodyScript.  The only other thing to note is that the regKey variable is different from the headScript() version.  This is to keep them separate when building the registered entities for this helper.</p>
<p>And of course, this is simply called just like HeadScript</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1008code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10084"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1008code4"><div class="php" style="font-family:monospace;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bodyScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span></div></td></tr></table></div>

<p><a href="http://aaronsaray.com/blog/2012/01/31/creating-a-custom-zend-framework-body-script-helper/">Creating a custom Zend Framework Body Script helper</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=q4cBZJAHIvc:tN3zNPTOd7k:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=q4cBZJAHIvc:tN3zNPTOd7k:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=q4cBZJAHIvc:tN3zNPTOd7k:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/q4cBZJAHIvc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2012/01/31/creating-a-custom-zend-framework-body-script-helper/</feedburner:origLink></item>
		<item>
		<title>Split Read/Write Connections in Zend Framework Database on the Application Level</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/g0lihGqTdt8/</link>
		<comments>http://aaronsaray.com/blog/2012/01/24/split-readwrite-connections-in-zend-framework-database-on-the-application-level/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 15:40:41 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/?p=1044</guid>
		<description><![CDATA[I&#8217;m no sys admin, so I can&#8217;t be sure, but I&#8217;ve seen lots of issues with using things like MySQL Proxy to fully separate the write and read queries in an application. Maybe it works, I don&#8217;t know&#8230; but I &#8230; <a href="http://aaronsaray.com/blog/2012/01/24/split-readwrite-connections-in-zend-framework-database-on-the-application-level/">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://aaronsaray.com/blog/2012/01/24/split-readwrite-connections-in-zend-framework-database-on-the-application-level/">Split Read/Write Connections in Zend Framework Database on the Application Level</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m no sys admin, so I can&#8217;t be sure, but I&#8217;ve seen lots of issues with using things like MySQL Proxy to fully separate the write and read queries in an application.  Maybe it works, I don&#8217;t know&#8230; but I do know that if I can separate the connections in my code, that saves my Admin time&#8230; it doesn&#8217;t appear to give that much of a hit to performance either!  Do keep in mind that this is only working at the table level in Zend Framework.  If you use their database system, this should do the trick.  If you do a lot of getting the adapter yourself, this won&#8217;t help you at all!</p>
<p>First thing to know, when you define your database settings in the application.ini file, the default settings that the bootstrap would read in &#8230; you know: </p>
<pre>
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "xx"
resources.db.params.password = "xx"
resources.db.params.dbname = "xx"
</pre>
<p>Let that be the read connection.</p>
<p>Next, create a method in your bootstrap called _initWriteConnection() or something like that.  Create the write connection in there (a separate instance of the Zend_Db connection&#8230;).  Store that into the Zend_Registry.</p>
<p>Finally, time to extend the Zend_Db_Table_Abstract</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1044code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10447"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code" id="p1044code7"><div class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Application_Model_SplitReadWriteDatabaseConnection <span style="color: #000000; font-weight: bold;">extends</span> Zend_Db_Table_Abstract<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* temporary storage of the read only adapter<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_readDB</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* invokes the read/write connection<br />
&nbsp; &nbsp; &nbsp;* @see Db/Table/Zend_Db_Table_Abstract::insert()<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insert<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_preWrite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_postWrite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Invokes the read/write connection<br />
&nbsp; &nbsp; &nbsp;* @see Db/Table/Zend_Db_Table_Abstract::update()<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$where</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_preWrite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$where</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_postWrite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Stores the read adapter and sets the write adapter<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _preWrite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_readDB <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAdapter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_setAdapter<span style="color: #009900;">&#40;</span>Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DbWriteConnection'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Sets the read adapter back and clears the temporary storage<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> _postWrite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_setAdapter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_readDB<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_readDB <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></table></div>

<p>This is pretty simple.  It overrides the insert and update commands of the Zend_Db_Table_Abstract class.  With that, it calls preWrite to set the adapter to the write version, and store the &#8216;current&#8217; one (the read one).  After the parent is called, it restores the database connection.</p>
<p><strong>This isn&#8217;t fully tested or complete!</strong></p>
<p>I&#8217;m trying to find ways to make this better.  Here are things/problems (err&#8230; Opportunities?) I see&#8230;</p>
<ul>
<li>If you use the getAdapter() method against a table, it will return the read connection.  You have to use the Zend_Db_Table methods only for this to work.</li>
<li>If an exception happens during the write methods, it may not return the connection to the read database.  I believe it will exit this code and continue using the write connection (even if more read queries are called).</li>
</ul>
<p>Any other ways that I can make this better?</p>
<p>PS, if you&#8217;d like to test this, but don&#8217;t actually have two different database credential connections (but want to be ready for later), make the _initWriteConnection() method contain the following code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1044code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10448"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1044code8"><div class="php" style="font-family:monospace;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'db'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'db'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DbWriteConnection'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$db</span><span style="color: #339933;">;</span></div></td></tr></table></div>

<p>This way, it gets the existing read connection and stores it as the &#8216;write&#8217; version as well.  Remember, only do this until you have both connections.</p>
<p><a href="http://aaronsaray.com/blog/2012/01/24/split-readwrite-connections-in-zend-framework-database-on-the-application-level/">Split Read/Write Connections in Zend Framework Database on the Application Level</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=g0lihGqTdt8:t_5P5EYQ_ps:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=g0lihGqTdt8:t_5P5EYQ_ps:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=g0lihGqTdt8:t_5P5EYQ_ps:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/g0lihGqTdt8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2012/01/24/split-readwrite-connections-in-zend-framework-database-on-the-application-level/</feedburner:origLink></item>
		<item>
		<title>Zend Framework Static Router URLs Not Found in Zend Navigation</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/htOYVnf3LGk/</link>
		<comments>http://aaronsaray.com/blog/2012/01/17/zend-framework-static-router-urls-not-found-in-zend-navigation/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 14:33:03 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/?p=988</guid>
		<description><![CDATA[For a CMS I&#8217;ve been working on, there are a number of custom routes that are added statically in a loop. These point to specific ID&#8217;s of articles on on the default module&#8217;s page viewing controller/action. Sometimes these routes need &#8230; <a href="http://aaronsaray.com/blog/2012/01/17/zend-framework-static-router-urls-not-found-in-zend-navigation/">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://aaronsaray.com/blog/2012/01/17/zend-framework-static-router-urls-not-found-in-zend-navigation/">Zend Framework Static Router URLs Not Found in Zend Navigation</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>For a CMS I&#8217;ve been working on, there are a number of custom routes that are added statically in a loop.  These point to specific ID&#8217;s of articles on on the default module&#8217;s page viewing controller/action.  Sometimes these routes need to appear in the Zend_Navigation output.  As you can probably guess, the logic used for this is similar to what you might experience when using the URL view helper.  But, for some reason, I could never get the URL&#8217;s to be marked as active.</p>
<p>Here is an example of the code that was being executed in the setup plugin:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p988code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p98811"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" id="p988code11"><div class="php" style="font-family:monospace;"><span style="color: #000088;">$route</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Router_Route_Static<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">'custom-url-1'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'module'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'default'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'controller'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'page'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'action'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'view'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">101</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #000088;">$router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRoute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'custom1'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$route</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$route</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Router_Route_Static<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">'custom-url-2'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'module'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'default'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'controller'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'page'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'action'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'view'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">102</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #000088;">$router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRoute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'custom2'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$route</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></table></div>

<p>Well, it turns out that its impossible for the URL handler to know which route to use.  It can match it, sure, but it doesn&#8217;t know how to recompile it (that&#8217;s my best guess at least&#8230;).  So, in order to tell it to form it in the default way, I added the &#8216;route&#8217;=>&#8217;default&#8217; attribute to the arrays and this seemed to work.</p>
<p>So now, for example, this is what you&#8217;ll find:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p988code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p98812"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p988code12"><div class="php" style="font-family:monospace;">&nbsp; &nbsp;<a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'module'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'default'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'controller'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'page'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'action'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'view'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">102</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'route'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'default'</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#41;</span></div></td></tr></table></div>

<p>Hope this helps someone else out!  If you know exactly why this works, feel free to comment.
<p><a href="http://aaronsaray.com/blog/2012/01/17/zend-framework-static-router-urls-not-found-in-zend-navigation/">Zend Framework Static Router URLs Not Found in Zend Navigation</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=htOYVnf3LGk:fgpe2XzS__E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=htOYVnf3LGk:fgpe2XzS__E:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=htOYVnf3LGk:fgpe2XzS__E:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/htOYVnf3LGk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2012/01/17/zend-framework-static-router-urls-not-found-in-zend-navigation/</feedburner:origLink></item>
		<item>
		<title>How to Quickly Mask a Credit Card Number</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/wBUATOX9KBQ/</link>
		<comments>http://aaronsaray.com/blog/2012/01/10/how-to-quickly-mask-a-credit-card-number/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 15:01:51 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/?p=1025</guid>
		<description><![CDATA[So, often I have to show a masked credit card on the screen. However, I really want to go the extra mile and show the user a secure, fully masked credit card number that still reflects their original card. For &#8230; <a href="http://aaronsaray.com/blog/2012/01/10/how-to-quickly-mask-a-credit-card-number/">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://aaronsaray.com/blog/2012/01/10/how-to-quickly-mask-a-credit-card-number/">How to Quickly Mask a Credit Card Number</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>So, often I have to show a masked credit card on the screen.  However, I really want to go the extra mile and show the user a secure, fully masked credit card number that still reflects their original card.  For example, if their credit card number is only 15 numbers long, I shouldn&#8217;t show a 16 character long string.  So, I&#8217;ve developed this code snippet:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1025code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p102514"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1025code14"><div class="php" style="font-family:monospace;"><span style="color: #000088;">$cc</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'1234123412341234'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$masked</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_pad"><span style="color: #990000;">str_pad</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cc</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'*'</span><span style="color: #339933;">,</span> STR_PAD_LEFT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></table></div>

<p>This simply takes the credit card, substr() the last 4 digit into the str_pad() method as the input.  Then, says the length of the output string should be strlen() of the actual input.  The pad character is a *.  Finally, pad everything on the left.  This way, no matter what, the output length will be the same as the input string, and it will be padded correctly.
<p><a href="http://aaronsaray.com/blog/2012/01/10/how-to-quickly-mask-a-credit-card-number/">How to Quickly Mask a Credit Card Number</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=wBUATOX9KBQ:ONpG2Q9QCIY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=wBUATOX9KBQ:ONpG2Q9QCIY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=wBUATOX9KBQ:ONpG2Q9QCIY:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/wBUATOX9KBQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2012/01/10/how-to-quickly-mask-a-credit-card-number/</feedburner:origLink></item>
		<item>
		<title>Running PHPUnit on Remote System from Command Line</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/_v7pcJc3d1E/</link>
		<comments>http://aaronsaray.com/blog/2012/01/03/running-phpunit-on-remote-system-from-command-line/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 16:19:05 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Eclipse PDT]]></category>
		<category><![CDATA[phpunit]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/?p=1050</guid>
		<description><![CDATA[If I need to run PHPUnit on a remote system against a code suite, I will write a simple shell script like the following to do it for me. (Bonus points, you can even include this as an External Tool &#8230; <a href="http://aaronsaray.com/blog/2012/01/03/running-phpunit-on-remote-system-from-command-line/">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://aaronsaray.com/blog/2012/01/03/running-phpunit-on-remote-system-from-command-line/">Running PHPUnit on Remote System from Command Line</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>If I need to run PHPUnit on a remote system against a code suite, I will write a simple shell script like the following to do it for me.  (Bonus points, you can even include this as an External Tool in eclipse to do it right from your project).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1050code16'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p105016"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1050code16"><div class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">ssh</span> developmentserver <span style="color: #ff0000;">&quot;cd /var/www/tests &amp;&amp; phpunit $1&quot;</span></div></td></tr></table></div>

<p>So, two things you should know: I&#8217;m using shared keys and have my .ssh/config file set up to have developmentserver as a name for the connection. </p>
<p><strong>Bonus:</strong></p>
<p>To add this as an external tool in Eclipse, do the following:</p>
<ol>
<li>Open Eclipse</li>
<li>Click Run -> External Tools -> External Tools Configurations</li>
<li>Double click &#8216;Program&#8217; to create a new program.</li>
<li>Name it to reflect the unit test you&#8217;re going to be running.</li>
<li>In the location box, put the full location to your bash script</li>
<li>In the arguments box, click Variables. Choose &#8216;selected resource location&#8217;</li>
<li>Click Apply/Close</li>
</ol>
<p>Now, assuming that your workspace is matched up to your file system on the remote system, you can run the external tool for PHP Unit on any selected test or folder.  The output will appear in your console tab.</p>
<p><a href="http://aaronsaray.com/blog/2012/01/03/running-phpunit-on-remote-system-from-command-line/">Running PHPUnit on Remote System from Command Line</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=_v7pcJc3d1E:JauDy6Nw1w8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=_v7pcJc3d1E:JauDy6Nw1w8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=_v7pcJc3d1E:JauDy6Nw1w8:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/_v7pcJc3d1E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2012/01/03/running-phpunit-on-remote-system-from-command-line/</feedburner:origLink></item>
		<item>
		<title>Mod Rewrite to index.php file, the easy way</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/YEGmHrnw63M/</link>
		<comments>http://aaronsaray.com/blog/2011/12/27/mod-rewrite-to-index-php-file-the-easy-way/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 16:17:48 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/?p=1058</guid>
		<description><![CDATA[How many of you have written this before (or something very much like it): ?View Code APACHE1 2 3 4 5 6 RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - &#8230; <a href="http://aaronsaray.com/blog/2011/12/27/mod-rewrite-to-index-php-file-the-easy-way/">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://aaronsaray.com/blog/2011/12/27/mod-rewrite-to-index-php-file-the-easy-way/">Mod Rewrite to index.php file, the easy way</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>How many of you have written this before (or something very much like it):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1058code19'); return false;">View Code</a> APACHE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p105819"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1058code19"><div class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} -s [OR]<br />
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} -l [OR]<br />
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} -f [OR]<br />
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} -d<br />
<span style="color: #00007f;">RewriteRule</span> ^.*$ - [NC,L]<br />
<span style="color: #00007f;">RewriteRule</span> ^.*$ index.php [NC,L]</div></td></tr></table></div>

<p>You might recognize something like this from the Zend Framework .htaccess file.  Basically, the point is to say if something doesn&#8217;t exist, point it to the index.php file.  Well, there is a simpler way to do this &#8211; I can&#8217;t believe I didn&#8217;t know this till now&#8230;</p>
<p><a href="http://httpd.apache.org/docs/2.3/mod/mod_dir.html#fallbackresource">Apache Fallback Resource</a></p>
<p>All of that configuration now becomes this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1058code20'); return false;">View Code</a> APACHE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p105820"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1058code20"><div class="apache" style="font-family:monospace;">FallbackResource /index.php</div></td></tr></table></div>

<p><a href="http://aaronsaray.com/blog/2011/12/27/mod-rewrite-to-index-php-file-the-easy-way/">Mod Rewrite to index.php file, the easy way</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=YEGmHrnw63M:EDiuXiBfomQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=YEGmHrnw63M:EDiuXiBfomQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=YEGmHrnw63M:EDiuXiBfomQ:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/YEGmHrnw63M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2011/12/27/mod-rewrite-to-index-php-file-the-easy-way/</feedburner:origLink></item>
		<item>
		<title>Add PHPUnit Listeners to Watch for Long Running Tests</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/9NLhhPq1rEg/</link>
		<comments>http://aaronsaray.com/blog/2011/12/20/add-phpunit-listeners-to-watch-for-long-running-tests/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 15:49:45 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[phpunit]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/?p=1053</guid>
		<description><![CDATA[One of the under-utilized features of PHPUnit probably is the listeners interface. You can see the configuration options here: http://www.phpunit.de/manual/current/en/appendixes.configuration.html. So, I decided that I want to use this to know if a Unit Test takes longer than 2 seconds &#8230; <a href="http://aaronsaray.com/blog/2011/12/20/add-phpunit-listeners-to-watch-for-long-running-tests/">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://aaronsaray.com/blog/2011/12/20/add-phpunit-listeners-to-watch-for-long-running-tests/">Add PHPUnit Listeners to Watch for Long Running Tests</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>One of the under-utilized features of PHPUnit probably is the listeners interface.  You can see the configuration options here: <a href="http://www.phpunit.de/manual/current/en/appendixes.configuration.html">http://www.phpunit.de/manual/current/en/appendixes.configuration.html</a>.  So, I decided that I want to use this to know if a Unit Test takes longer than 2 seconds to run.  That&#8217;s super over-kill in my opinion, but that&#8217;s my hard limit.  If it takes longer than 2 seconds to run, something is wrong!  So, I added the following to my configuration:</p>
<p><strong>excerpt from phpunit.xml</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1053code23'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p105323"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1053code23"><div class="xml" style="font-family:monospace;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listeners<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;scripts/TestTimesLimitListener.php&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;Application_Test_TestTimesListener&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listeners<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></table></div>

<p>This simply says to invoke the listener from TestTimesLimitListener.php &#8211; which class name is Application_test_TestTimesListener.  Here is the code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1053code24'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p105324"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
</pre></td><td class="code" id="p1053code24"><div class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* Listener Class for test times<br />
&nbsp;* <br />
&nbsp;* @package Tests<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">class</span> Application_Test_TestTimesListener implements PHPUnit_Framework_TestListener<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Number of seconds that this test can run<br />
&nbsp; &nbsp; &nbsp;* @var integer<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">const</span> TEST_LIMIT_TIME <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* called when test is ended - determines if it was long and prints<br />
&nbsp; &nbsp; &nbsp;* @param PHUnit_Framework_Test $test<br />
&nbsp; &nbsp; &nbsp;* @param float $length the length of time for the test<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> endTest<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span> <span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">TEST_LIMIT_TIME</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_printError<span style="color: #009900;">&#40;</span><span style="color: #000088;">$test</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; ran for <span style="color: #006699; font-weight: bold;">{$length}</span> seconds&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Used to print error in error colors<br />
&nbsp; &nbsp; &nbsp;* @param string $error<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _printError<span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #660099; font-weight: bold;">\033</span>[41m&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$error</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\033</span>[0m<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Required for Interface<br />
&nbsp; &nbsp; &nbsp;* (non-PHPdoc)<br />
&nbsp; &nbsp; &nbsp;* @see PHPUnit_Framework_TestListener::startTest()<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> startTest<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Required for Interface<br />
&nbsp; &nbsp; &nbsp;* (non-PHPdoc)<br />
&nbsp; &nbsp; &nbsp;* @see PHPUnit_Framework_TestListener::addError()<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addError<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> Exception <span style="color: #000088;">$e</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Required for Interface<br />
&nbsp; &nbsp; &nbsp;* (non-PHPdoc)<br />
&nbsp; &nbsp; &nbsp;* @see PHPUnit_Framework_TestListener::addFailure()<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addFailure<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> PHPUnit_Framework_AssertionFailedError <span style="color: #000088;">$e</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Required for Interface<br />
&nbsp; &nbsp; &nbsp;* (non-PHPdoc)<br />
&nbsp; &nbsp; &nbsp;* @see PHPUnit_Framework_TestListener::addError()<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addIncompleteTest<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> Exception <span style="color: #000088;">$e</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Required for Interface<br />
&nbsp; &nbsp; &nbsp;* (non-PHPdoc)<br />
&nbsp; &nbsp; &nbsp;* @see PHPUnit_Framework_TestListener::addSkippedTest()<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addSkippedTest<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> Exception <span style="color: #000088;">$e</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Required for Interface<br />
&nbsp; &nbsp; &nbsp;* (non-PHPdoc)<br />
&nbsp; &nbsp; &nbsp;* @see PHPUnit_Framework_TestListener::startTestSuite()<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> startTestSuite<span style="color: #009900;">&#40;</span>PHPUnit_Framework_TestSuite <span style="color: #000088;">$suite</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Required for Interface<br />
&nbsp; &nbsp; &nbsp;* (non-PHPdoc)<br />
&nbsp; &nbsp; &nbsp;* @see PHPUnit_Framework_TestListener::endTestSuite()<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> endTestSuite<span style="color: #009900;">&#40;</span>PHPUnit_Framework_TestSuite <span style="color: #000088;">$suite</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span> <br />
<span style="color: #009900;">&#125;</span></div></td></tr></table></div>

<p>First of all, the class must implement the PHPUnit_Framework_TestListener interface.  That&#8217;s why at the end you&#8217;ll see all the extra empty methods piled on.  Let&#8217;s dive into the code:</p>
<p>Define a constant of the number of whole seconds.  Next, define the endTest method which will receive a float of how many seconds/milliseconds that test took to run.  If it takes longer than our limit, print an error using the test name.  The _printError() method uses some control characters to change the font color red.  </p>
<p>There you go!  Now, during your normal execution of unit tests, you may see a few warnings for long running tests in red.  Go and correct those to keep your tests running smooth and fast.</p>
<p>Please note: a while ago, I ran into a blog entry about this.  It wasn&#8217;t clear to me at the time, so I didn&#8217;t book mark it.  However, I wanted to mention that this isn&#8217;t 100% only my work.  Credit to where credit is due.</p>
<p><a href="http://aaronsaray.com/blog/2011/12/20/add-phpunit-listeners-to-watch-for-long-running-tests/">Add PHPUnit Listeners to Watch for Long Running Tests</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=9NLhhPq1rEg:EqUM-2EJESI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=9NLhhPq1rEg:EqUM-2EJESI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=9NLhhPq1rEg:EqUM-2EJESI:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/9NLhhPq1rEg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2011/12/20/add-phpunit-listeners-to-watch-for-long-running-tests/</feedburner:origLink></item>
		<item>
		<title>Setting PHP Command Line Colors</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/4uFmd0CgcA8/</link>
		<comments>http://aaronsaray.com/blog/2011/12/14/setting-php-command-line-colors/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 16:50:43 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/?p=1056</guid>
		<description><![CDATA[I&#8217;m not entirely certain why this escaped me for so long, but it&#8217;s remarkably easy to set terminal colors with PHP. Simply echo the escape/color character \033, followed by the bash color definition and your output. For reference, here is &#8230; <a href="http://aaronsaray.com/blog/2011/12/14/setting-php-command-line-colors/">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://aaronsaray.com/blog/2011/12/14/setting-php-command-line-colors/">Setting PHP Command Line Colors</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not entirely certain why this escaped me for so long, but it&#8217;s remarkably easy to set terminal colors with PHP.  Simply echo the escape/color character \033, followed by the bash color definition and your output.  For reference, <a href="https://wiki.archlinux.org/index.php/Color_Bash_Prompt">here</a> is a listing of bash colors.  So, for example, if we want to make something blue text, do the following:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1056code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p105626"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1056code26"><div class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\033</span>[34m&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'here is blue text'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\033</span>[0m<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></div></td></tr></table></div>

<p>This simply sets the blue color, adds the blue text, and then resets the color to default, and makes a new line.
<p><a href="http://aaronsaray.com/blog/2011/12/14/setting-php-command-line-colors/">Setting PHP Command Line Colors</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=4uFmd0CgcA8:O8-j8X39bOg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=4uFmd0CgcA8:O8-j8X39bOg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=4uFmd0CgcA8:O8-j8X39bOg:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/4uFmd0CgcA8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2011/12/14/setting-php-command-line-colors/</feedburner:origLink></item>
		<item>
		<title>When you Create Your Account, Please log in.</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/SBDUvZAlJUc/</link>
		<comments>http://aaronsaray.com/blog/2011/12/06/when-you-create-your-account-please-log-in/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 15:33:56 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Misc Web Design]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/?p=1060</guid>
		<description><![CDATA[I&#8217;ve always found it annoying when programmers create systems where you create your account and then you&#8217;re not logged in. Maybe I&#8217;m lazy? I decided to do a poll on a popular social networking site. The poll went like this: &#8230; <a href="http://aaronsaray.com/blog/2011/12/06/when-you-create-your-account-please-log-in/">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://aaronsaray.com/blog/2011/12/06/when-you-create-your-account-please-log-in/">When you Create Your Account, Please log in.</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always found it annoying when programmers create systems where you create your account and then you&#8217;re not logged in.  Maybe I&#8217;m lazy?  I decided to do a poll on a popular social networking site.  The poll went like this:</p>
<p><strong>When signing up for a new web site, do you mind logging in after signing up?</strong></p>
<p>The two options were:</p>
<ul>
<li><strong>If I create an account, it should already log me in.</strong></li>
<li><strong>I don&#8217;t mind logging in after I create my account (it proves I know my password)</strong></li>
</ul>
<p>Overwhelmingly (ok only 78% but still&#8230;) response has been in favor of creating an account and logging in automatically.  I think that we should take the extra step when creating applications to make this process streamlined for users.
<p><a href="http://aaronsaray.com/blog/2011/12/06/when-you-create-your-account-please-log-in/">When you Create Your Account, Please log in.</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=SBDUvZAlJUc:tXY-G8uqaoI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=SBDUvZAlJUc:tXY-G8uqaoI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=SBDUvZAlJUc:tXY-G8uqaoI:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/SBDUvZAlJUc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2011/12/06/when-you-create-your-account-please-log-in/</feedburner:origLink></item>
		<item>
		<title>Zend Framework Authentication: Let the user know if it is their fault</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/1yHZM_YYPjs/</link>
		<comments>http://aaronsaray.com/blog/2011/11/29/zend-framework-authentication-let-the-user-know-if-it-is-their-fault/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 20:03:50 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/?p=1015</guid>
		<description><![CDATA[One of the things that is irritating is logging into a website with credentials that you know are right, only to have it fail. Then, later, you find that the site was malfunctioning. By then, maybe you requested a new &#8230; <a href="http://aaronsaray.com/blog/2011/11/29/zend-framework-authentication-let-the-user-know-if-it-is-their-fault/">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://aaronsaray.com/blog/2011/11/29/zend-framework-authentication-let-the-user-know-if-it-is-their-fault/">Zend Framework Authentication: Let the user know if it is their fault</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>One of the things that is irritating is logging into a website with credentials that you know are right, only to have it fail.  Then, later, you find that the site was malfunctioning.  By then, maybe you requested a new password, or had to at least waste time looking up your old password.  With Zend_Auth, however, we can prevent user&#8217;s from having that issue.</p>
<p>Side note: some schools of thought want to go the extra mile for security and never give the visitor any extra information than what is required.  I believe this to some extent.  I will say the username or password is wrong (I won&#8217;t say that the username exists, but the password is wrong.)  However, I don&#8217;t think it&#8217;s out of line to alert the user if your system is having authentication issues. </p>
<p>So, with Zend_Auth, the authenticate() method returns a Zend_Auth_Result.  This, of course, has the isValid() method which everyone is familiar with.  However, there are a number of reasons why this could return false.  Whatever reason generated the invalid response will be returned by the getCode() method.  These include:</p>
<pre>
    const FAILURE                        =  0;
    const FAILURE_IDENTITY_NOT_FOUND     = -1;
    const FAILURE_IDENTITY_AMBIGUOUS     = -2;
    const FAILURE_CREDENTIAL_INVALID     = -3;
    const FAILURE_UNCATEGORIZED          = -4;
</pre>
<p>The user is really only concerned with the FAILURE_IDENTITY_NOT_FOUND and FAILURE_CREDENTIAL_INVALID conditions.  The rest are more-than-likely our own failures.  (For example, your data has become corrupted? FAILURE_IDENTITY_AMBIGUOUS).  </p>
<p>When I generate error messages for the user, I tend to make a method called isFailureUserBased() which will determine the type of error I return.  If it is user based, I&#8217;ll return a string saying incorrect username or password.  If it is not user based, the message will be to contact support or wait it out (I might even send an automated note to the support staff at this time).</p>
<p>This is usually a very simple method:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1015code28'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p101528"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p1015code28"><div class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* Used to determine if this is a user failure or an internal failure on our part<br />
&nbsp;* <br />
&nbsp;* @return boolean if its a user failure<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isFailureUserBased<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_authResult<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//stored internal Zend_Auth_Result instance</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> Zend_Auth_Result<span style="color: #339933;">::</span><span style="color: #004000;">FAILURE_IDENTITY_NOT_FOUND</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> Zend_Auth_Result<span style="color: #339933;">::</span><span style="color: #004000;">FAILURE_CREDENTIAL_INVALID</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></table></div>

<p><a href="http://aaronsaray.com/blog/2011/11/29/zend-framework-authentication-let-the-user-know-if-it-is-their-fault/">Zend Framework Authentication: Let the user know if it is their fault</a> is a post from: <a href="http://aaronsaray.com">Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=1yHZM_YYPjs:rrh5Cwyui8M:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=1yHZM_YYPjs:rrh5Cwyui8M:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=1yHZM_YYPjs:rrh5Cwyui8M:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/1yHZM_YYPjs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2011/11/29/zend-framework-authentication-let-the-user-know-if-it-is-their-fault/</feedburner:origLink></item>
	</channel>
</rss>

