<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Turboflash's Blog</title>
	<atom:link href="http://turboflash.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://turboflash.wordpress.com</link>
	<description>TurboFlash</description>
	<lastBuildDate>Wed, 08 Jun 2011 23:36:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='turboflash.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Turboflash's Blog</title>
		<link>http://turboflash.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://turboflash.wordpress.com/osd.xml" title="Turboflash&#039;s Blog" />
	<atom:link rel='hub' href='http://turboflash.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Apache: Environment Variables Visibility with SetEnv, SetEnvIf and RewriteRule Directives</title>
		<link>http://turboflash.wordpress.com/2010/05/27/apache-environment-variables-visibility-with-setenv-setenvif-and-rewriterule-directives/</link>
		<comments>http://turboflash.wordpress.com/2010/05/27/apache-environment-variables-visibility-with-setenv-setenvif-and-rewriterule-directives/#comments</comments>
		<pubDate>Wed, 26 May 2010 16:00:11 +0000</pubDate>
		<dc:creator>turboflash</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Environment Variables]]></category>
		<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Allow]]></category>
		<category><![CDATA[Deny]]></category>
		<category><![CDATA[Directives]]></category>
		<category><![CDATA[Environment]]></category>
		<category><![CDATA[Header]]></category>
		<category><![CDATA[IfDefine]]></category>
		<category><![CDATA[mod_authz_host]]></category>
		<category><![CDATA[mod_env]]></category>
		<category><![CDATA[mod_headers]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[mod_setenvif]]></category>
		<category><![CDATA[RewriteRule]]></category>
		<category><![CDATA[SetEnv]]></category>
		<category><![CDATA[SetEnvIf]]></category>
		<category><![CDATA[Variables]]></category>
		<category><![CDATA[Visibility]]></category>

		<guid isPermaLink="false">http://turboflash.wordpress.com/?p=290</guid>
		<description><![CDATA[Scenario One of those moments again where the search engine did not turn up information which I need. So I hope this article will be helpful to someone out there. It seems that environment variables in Apache are not being treated equally when SetEnv, SetEnvIf and RewriteRule directives are used. In my case, I want [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=290&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Scenario</h2>
<p>One of those moments again where the search engine did not turn up information which I need. So I hope this article will be helpful to someone out there.</p>
<p>It seems that environment variables in Apache are not being treated equally when <span style="font-family:Courier New;">SetEnv</span>, <span style="font-family:Courier New;">SetEnvIf</span> and <span style="font-family:Courier New;">RewriteRule</span> directives are used. In my case, I want to limit access based on query string but <span style="font-family:Courier New;">SetEnvIf</span> does not have that attribute to test against. <span style="font-family:Courier New;">RewriteRule</span> creates an environment variable that is not accessible by <span style="font-family:Courier New;">Allow/Deny</span> directive (Possibly because <span style="font-family:Courier New;">Allow/Deny</span> are evaluated before <span style="font-family:Courier New;">RewriteRule</span>). It makes things complicated when you are going to use environment variables to limit access but it does not work as expected.</p>
<p>Unfortunately, I do not have a solution for you but I hope this information will save you countless hours researching a solution that never exists. But if you do have one, please let me know as I would love to hear from you.</p>
<h2>.htaccess Test Configuration</h2>
<p>You can <a href="#Summary_1">skip</a> this part actually. But if you are interested in how the test is done, you can continue reading.</p>
<p><pre class="brush: plain;">
RewriteEngine On

# Putting Header before setting the environment variables do not seem to matter.
Header always add A_1 &quot;%{A_1}e&quot;
Header always add B_1 &quot;%{B_1}e&quot;
Header always add C_1 &quot;%{C_1}e&quot;
Header always add U_1 &quot;%{U_1}e&quot;

Header always add A_2 &quot;%{A_2}e&quot;
Header always add B_2 &quot;%{B_2}e&quot;
Header always add C_2 &quot;%{C_2}e&quot;
Header always add U_2 &quot;%{U_2}e&quot;

Header always add A_3 &quot;%{A_3}e&quot;
Header always add B_3 &quot;%{B_3}e&quot;
Header always add C_3 &quot;%{C_3}e&quot;
Header always add U_3 &quot;%{U_3}e&quot;

Header always add A_4 &quot;%{A_4}e&quot;
Header always add B_4 &quot;%{B_4}e&quot;
Header always add C_4 &quot;%{C_4}e&quot;
Header always add U_4 &quot;%{U_4}e&quot;

Header always add A_5 &quot;%{A_5}e&quot;
Header always add B_5 &quot;%{B_5}e&quot;
Header always add C_5 &quot;%{C_5}e&quot;
Header always add U_5 &quot;%{U_5}e&quot;
Header always add S_5 &quot;%{S_5}e&quot;

# Test to see if (1) Header can access the environment variables.
SetEnv A_1 SetEnv_Works
SetEnvIf always_match ^ B_1=SetEnvIf_Works
RewriteRule .* - [E=C_1:RewriteRule_Works,NE]
# U_1 is not set deliberately.

# Test to see if (2) SetEnvIf can access the environment variables.
SetEnvIf A_1 ^(.*)$ A_2=&quot;$1&quot;
SetEnvIf B_1 ^(.*)$ B_2=&quot;$1&quot;
SetEnvIf C_1 ^(.*)$ C_2=&quot;$1&quot;
SetEnvIf U_1 ^(.*)$ U_2=&quot;$1&quot;

# Test to see if (3) RewriteCond can access the environment variables.
RewriteCond %{ENV:A_1} ^(.*)$
RewriteRule .* - [E=A_3:&quot;%1&quot;,NE]
RewriteCond %{ENV:B_1} ^(.*)$
RewriteRule .* - [E=B_3:&quot;%1&quot;,NE]
RewriteCond %{ENV:C_1} ^(.*)$
RewriteRule .* - [E=C_3:&quot;%1&quot;,NE]
RewriteCond %{ENV:U_1} ^(.*)$
RewriteRule .* - [E=U_3:&quot;%1&quot;,NE]

# Test to see if (4) RewriteRule can access the environment variables.
RewriteRule .* - [E=A_4:&quot;%{ENV:A_1}&quot;,NE]
RewriteRule .* - [E=B_4:&quot;%{ENV:B_1}&quot;,NE]
RewriteRule .* - [E=C_4:&quot;%{ENV:C_1}&quot;,NE]
RewriteRule .* - [E=U_4:&quot;%{ENV:U_1}&quot;,NE]

# Test to see if (5) &lt;IfDefine&gt; can access the environment variables.
&lt;IfDefine A_1&gt;
    SetEnv A_5 Can_Access
&lt;/IfDefine&gt;
&lt;IfDefine B_1&gt;
    SetEnv B_5 Can_Access
&lt;/IfDefine&gt;
&lt;IfDefine C_1&gt;
    SetEnv C_5 Can_Access
&lt;/IfDefine&gt;
&lt;IfDefine U_1&gt;
    SetEnv U_5 Can_Access
&lt;/IfDefine&gt;
SetEnv S_5 Unconditionally_Set

# Test to see if (6) Allow/Deny can access the environment variables.
Options +Indexes
Order Deny,Allow
Deny from all
# To test, only one should be uncommented at any point in time.
#Allow from env=A_1
#Allow from env=B_1
#Allow from env=C_1
#Allow from env=U_1
Allow from all    # Required for (3) RewriteCond and (4) RewriteRule test to work properly.
</pre></p>
<h2>Test Result</h2>
<p><pre class="brush: plain;">
A_1	SetEnv_Works
B_1	SetEnvIf_Works
C_1	RewriteRule_Works
U_1	(null)
A_2	&quot;&quot;
B_2	&quot;SetEnvIf_Works&quot;
C_2	&quot;&quot;
U_2	&quot;&quot;
A_3	&quot;&quot;
B_3	&quot;SetEnvIf_Works&quot;
C_3	&quot;RewriteRule_Works&quot;
U_3	&quot;&quot;
A_4	&quot;&quot;
B_4	&quot;SetEnvIf_Works&quot;
C_4	&quot;RewriteRule_Works&quot;
U_4	&quot;&quot;
A_5	(null)
B_5	(null)
C_5	(null)
U_5	(null)
S_5	Unconditionally_Set
</pre></p>
<p><a id="Summary" name="Summary_1"> </a></p>
<h2>Summary</h2>
<table border="1" style="border-collapse:collapse;border-left:none;border-top:none;">
<tbody>
<tr>
<td style="border-top:none;border-left:none;" colspan="2" rowspan="2"></td>
<td style="background:#B8B8B8;border-top:solid black 1px;text-align:center;" colspan="3"><strong>Set Using</strong></td>
<td style="background:#B8B8B8;border-top:solid black 1px;text-align:center;" rowspan="2"><strong>(U)</strong><br />
<strong>Unset</strong><br />
<strong>Variable</strong></td>
</tr>
<tr>
<td style="background:#B8B8B8;text-align:center;"><strong>(A)</strong><br />
<strong>SetEnv</strong></td>
<td style="background:#B8B8B8;text-align:center;"><strong>(B)</strong><br />
<strong>SetEnvIf</strong></td>
<td style="background:#B8B8B8;text-align:center;"><strong>(C)</strong><br />
<strong>RewriteRule<br />
</strong></td>
</tr>
<tr>
<td style="background:#B8B8B8;border-left:solid black 1px;text-align:center;" rowspan="6"><strong>Accessible By</strong></td>
<td style="background:#B8B8B8;"><strong>(1) Header</strong></td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>(null)</td>
</tr>
<tr>
<td style="background:#B8B8B8;"><strong>(2) SetEnvIf</strong></td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>-</td>
</tr>
<tr>
<td style="background:#B8B8B8;"><strong>(3) RewriteCond*</strong></td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>-</td>
</tr>
<tr>
<td style="background:#B8B8B8;"><strong>(4) RewriteRule*</strong></td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>-</td>
</tr>
<tr>
<td style="background:#B8B8B8;"><strong>(5) &lt;IfDefine&gt;</strong></td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td style="background:#B8B8B8;"><strong>(6) Allow/Deny<br />
</strong></td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>-</td>
</tr>
</tbody>
</table>
<p>*Will not work if &#8220;Deny from all&#8221; is in effect.</p>
<p>Excellent References:<br />
<a class="alignleft" title="Environment Variables in Apache" href="http://httpd.apache.org/docs/2.2/env.html" target="_blank">http://httpd.apache.org/docs/2.2/env.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/turboflash.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/turboflash.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/turboflash.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/turboflash.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/turboflash.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/turboflash.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/turboflash.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/turboflash.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/turboflash.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/turboflash.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/turboflash.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/turboflash.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/turboflash.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/turboflash.wordpress.com/290/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=290&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://turboflash.wordpress.com/2010/05/27/apache-environment-variables-visibility-with-setenv-setenvif-and-rewriterule-directives/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/439f31e58019ea93391bef3d7c8c352e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">turboflash</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows XP: Disable Autorun.inf</title>
		<link>http://turboflash.wordpress.com/2009/10/08/windows-xp-disable-autorun-inf/</link>
		<comments>http://turboflash.wordpress.com/2009/10/08/windows-xp-disable-autorun-inf/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 16:00:34 +0000</pubDate>
		<dc:creator>turboflash</dc:creator>
				<category><![CDATA[Windows XP]]></category>
		<category><![CDATA[Windows XP Disable Autorun Security]]></category>

		<guid isPermaLink="false">http://turboflash.wordpress.com/?p=267</guid>
		<description><![CDATA[As you may already be aware, Autorun is one of the malware infection means in Windows. I have been searching for the best way to disable Autorun that could really give me a peace of mind and have come across this article. Some background You can skip this part actually. But if you are interested [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=267&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As you may already be aware, Autorun is one of the malware infection means in Windows. I have been searching for the best way to disable Autorun that could really give me a peace of mind and have come across this <a title="Nick Brown's blog: Memory stick worms" href="http://nick.brown.free.fr/blog/2007/10/memory-stick-worms.html" target="_blank">article</a>.</p>
<h2>Some background</h2>
<p>You can <a href="#The_solution_2">skip</a> this part actually. But if you are interested in some technical details, you can continue reading. This post is written based on Windows XP but it should also work for other NT family of operating systems such as Windows 2000, Windows Vista, etc. Henceforth, any reference to Windows means Windows XP.</p>
<p>In Windows, <span style="font-family:Courier New;">.ini</span> files are now mapped to the Registry. What really happened is whenever a <span style="font-family:Courier New;">x.ini</span> file is referenced, it will look up the corresponding <span style="font-family:Courier New;">x.ini</span> in <span style="font-family:Courier New;">HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping</span>. It seems <span style="font-family:Courier New;">.inf</span> works in the same way too.</p>
<p>If you read through the <a title="Chapter 26 - Initialization Files and the Registry" href="http://www.microsoft.com/technet/archive/ntwrkstn/reskit/26_ini.mspx" target="_blank">Microsoft documentation</a>, you find an interesting symbol &#8220;<span style="font-family:Courier New;">@</span>&#8221; used in the value. What it does is it prevents any reads from going to the .ini file on disk if the requested data is not found in the Registry. Now we are all set for the solution.</p>
<p><a id="The solution" name="The_solution_2"> </a></p>
<h2>The solution</h2>
<p>Create a Registry file <span style="font-family:Courier New;">DisableAutorun.reg</span> with the following content and double-click on the newly created file to import the setting. That&#8217;s it.<br />
<pre class="brush: xml;">
Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\Autorun.inf]
; Assign a non-existence key to &quot;(Default)&quot;.
@=&quot;@SYS:DoesNotExist&quot;
</pre></p>
<p>Excellent References:<br />
<a class="alignleft" title="Nick Brown's blog: Memory stick worms" href="http://nick.brown.free.fr/blog/2007/10/memory-stick-worms.html" target="_blank">http://nick.brown.free.fr/blog/2007/10/memory-stick-worms.html</a><br />
<a class="alignleft" title="Chapter 26 - Initialization Files and the Registry" href="http://www.microsoft.com/technet/archive/ntwrkstn/reskit/26_ini.mspx" target="_blank">http://www.microsoft.com/technet/archive/ntwrkstn/reskit/26_ini.mspx</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/turboflash.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/turboflash.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/turboflash.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/turboflash.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/turboflash.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/turboflash.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/turboflash.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/turboflash.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/turboflash.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/turboflash.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/turboflash.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/turboflash.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/turboflash.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/turboflash.wordpress.com/267/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=267&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://turboflash.wordpress.com/2009/10/08/windows-xp-disable-autorun-inf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/439f31e58019ea93391bef3d7c8c352e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">turboflash</media:title>
		</media:content>
	</item>
		<item>
		<title>cURL: Adding/Installing/Trusting New Self-Signed Certificate</title>
		<link>http://turboflash.wordpress.com/2009/06/23/curl-adding-installing-trusting-new-self-signed-certificate/</link>
		<comments>http://turboflash.wordpress.com/2009/06/23/curl-adding-installing-trusting-new-self-signed-certificate/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 16:00:09 +0000</pubDate>
		<dc:creator>turboflash</dc:creator>
				<category><![CDATA[cURL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Add]]></category>
		<category><![CDATA[CA]]></category>
		<category><![CDATA[Certificate]]></category>
		<category><![CDATA[Install]]></category>
		<category><![CDATA[libcurl]]></category>
		<category><![CDATA[OpenID]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Self-Signed]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[Trust]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://turboflash.wordpress.com/?p=203</guid>
		<description><![CDATA[Scenario It has been that situation again when I have spent a whole day trying to research and figure out the solution to a problem that has bugged me. Hopefully this will save researching time for people having the same issue. If you, like me, are trying to get cURL, or rather, plugin such as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=203&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Scenario</h2>
<p>It has been that situation again when I have spent a whole day trying to research and figure out the solution to a problem that has bugged me. Hopefully this will save researching time for people having the same issue.</p>
<p>If you, like me, are trying to get <a title="cURL and libcurl" href="http://curl.haxx.se/" target="_blank">cURL</a>, or rather, plugin such as <a title="WordPress › OpenID &amp;laquo; WordPress Plugins" href="http://wordpress.org/extend/plugins/openid/" target="_blank">WordPress OpenID</a> (which uses PHP libcurl) to work with HTTPS sites that use self-signed certificates but do not wish to compromise the security by disabling <span style="font-family:Courier New;">CURLOPT_SSL_VERIFYPEER</span> and/or <span style="font-family:Courier New;">CURLOPT_SSL_VERIFYHOST</span> option in the code, the following might be the answer for you.</p>
<h2>Some background</h2>
<p>You can <a href="#The_solution_1">skip</a> this part actually. But if you are interested in some technical details, you can continue reading. This post is written on the assumption that Ubuntu Linux is used. It should apply to other distros as well with minor differences.</p>
<p>When we are using cURL to retrieve a HTTPS site that is not using a CA-signed certificate, the following problem occurs. Of course, this can simply be overcome by using the <span style="font-family:Courier New;">-k</span> option.</p>
<p><pre class="brush: bash;">
root@ubuntu:/etc# curl https://example.selfip.com
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a &quot;bundle&quot;
 of Certificate Authority (CA) public keys (CA certs). The default
 bundle is named curl-ca-bundle.crt; you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.
</pre></p>
<p>However, in the case of applications such as WordPress OpenID plugin, we have to amend the code to disable both <span style="font-family:Courier New;">CURLOPT_SSL_VERIFYPEER</span> and/or <span style="font-family:Courier New;">CURLOPT_SSL_VERIFYHOST</span>. Not a very good idea as this will disable verification for authentic sites as well. If we know <span style="font-family:Courier New;">example.selfip.com</span>, in this case is one of our own trusted test servers, we can add its certificate to the trusted list.</p>
<p>Now that we know what to do, we have to find out how to do it. It took me quite a while to look for the solution as I was looking in the wrong places. WordPress OpenID and cURL documentations/forums did not point me in the right direction. I decided to take a look at the source code in cURL and discover that ultimately, the responsibility of the verification lies with OpenSSL.</p>
<p>Arm with this and some right keyword searching, it has led me to this <a title="OpenSSL Command-Line HOWTO" href="http://www.madboa.com/geek/openssl/#verify-system" target="_blank">HOWTO</a>, which provided some insight on how OpenSSL recognizes certificate authorities, and an important <a title="Ubuntu Manpage: update-ca-certificates - update /etc/ssl/certs and certificates.crt" href="http://manpages.ubuntu.com/manpages/karmic/man8/update-ca-certificates.8.html" target="_blank">program</a>. Right now, we are all set to add the new certificate so that our OpenSSL can recognize the HTTPS server.</p>
<p><a id="The solution" name="The_solution_1"> </a></p>
<h2>The solution</h2>
<p>Identify which directory your OpenSSL installation uses.<br />
<pre class="brush: bash;">
root@ubuntu:~# openssl version -d
OPENSSLDIR: &quot;/usr/lib/ssl&quot;
</pre></p>
<p>Change to that directory.<br />
<pre class="brush: bash;">
root@ubuntu:~# cd /usr/lib/ssl
</pre></p>
<p>List the directory contents. You should see a directory called &#8220;certs&#8221;.<br />
<pre class="brush: bash;">
root@ubuntu:/usr/lib/ssl# ls -la
total 24
drwxr-xr-x  4 root root  4096 2009-04-24 14:37 .
drwxr-xr-x 50 root root 12288 2009-04-24 17:56 ..
lrwxrwxrwx  1 root root    14 2009-04-24 14:37 certs -&gt; /etc/ssl/certs
drwxr-xr-x  2 root root  4096 2009-04-24 14:37 engines
drwxr-xr-x  2 root root  4096 2009-04-24 14:37 misc
lrwxrwxrwx  1 root root    20 2009-04-24 14:37 openssl.cnf -&gt; /etc/ssl/openssl.cnf
lrwxrwxrwx  1 root root    16 2009-04-24 14:37 private -&gt; /etc/ssl/private
</pre></p>
<p>Change to that directory.<br />
<pre class="brush: bash;">
root@ubuntu:/usr/lib/ssl# cd certs
</pre></p>
<p>List the directory contents. You should see from the symlinks that the certificates are actually stored in &#8220;/usr/share/ca-certificates&#8221;.<br />
<pre class="brush: bash;">
root@ubuntu:/usr/lib/ssl/certs# ls -la
total 648
drwxr-xr-x 2 root root  16384 2009-06-24 12:32 .
drwxr-xr-x 4 root root   4096 2009-04-24 14:39 ..
lrwxrwxrwx 1 root root     26 2009-06-24 12:32 00673b5b.0 -&gt; thawte_Primary_Root_CA.pem
lrwxrwxrwx 1 root root     59 2009-06-24 12:32 2edf7016.0 -&gt; Verisign_Class_1_Public_Primary_Certification_Authority.pem
lrwxrwxrwx 1 root root     61 2009-06-24 12:32 thawte_Primary_Root_CA.pem -&gt; /usr/share/ca-certificates/mozilla/thawte_Primary_Root_CA.crt
lrwxrwxrwx 1 root root     94 2009-06-24 12:32 Verisign_Class_1_Public_Primary_Certification_Authority.pem -&gt; /usr/share/ca-certificates/mozilla/Verisign_Class_1_Public_Primary_Certification_Authority.crt
.
.
.
</pre></p>
<p>Change to that directory.<br />
<pre class="brush: bash;">
root@ubuntu:/usr/lib/ssl/certs# cd /usr/share/ca-certificates
</pre></p>
<p>List the directory contents. As you can see, I have added &#8220;example.selfip.com.crt&#8221; here.<br />
<pre class="brush: bash;">
root@ubuntu:/usr/share/ca-certificates# ls -la
total 56
drwxr-xr-x 11 root root  4096 2009-06-24 15:02 .
drwxr-xr-x 98 root root  4096 2009-04-24 17:51 ..
drwxr-xr-x  2 root root  4096 2009-04-24 14:35 brasil.gov.br
drwxr-xr-x  2 root root  4096 2009-04-24 14:35 cacert.org
drwxr-xr-x  2 root root  4096 2009-04-24 14:35 debconf.org
-rw-r--r--  1 root root  1220 2009-06-24 11:57 example.selfip.com.crt
drwxr-xr-x  2 root root  4096 2009-04-24 14:35 gouv.fr
drwxr-xr-x  2 root root 12288 2009-04-24 14:35 mozilla
drwxr-xr-x  2 root root  4096 2009-04-24 14:35 quovadis.bm
drwxr-xr-x  2 root root  4096 2009-04-24 14:35 signet.pl
drwxr-xr-x  2 root root  4096 2009-04-24 14:35 spi-inc.org
drwxr-xr-x  2 root root  4096 2009-04-24 14:35 telesec.de
</pre></p>
<p>Change to &#8220;/etc&#8221; directory and edit the file &#8220;ca-certificates.conf&#8221;.<br />
<pre class="brush: bash;">
root@ubuntu:/usr/share/ca-certificates# cd /etc
root@ubuntu:/etc# nano ca-certificates.conf
</pre></p>
<p>Add &#8220;example.selfip.com.crt&#8221; to the file and save it.<br />
<pre class="brush: bash;">
-------------------------------------------------------------------------------
  GNU nano 2.0.9                         File: ca-certificates.conf

# This file lists certificates that you wish to use or to ignore to be
# installed in /etc/ssl/certs.
# update-ca-certificates(8) will update /etc/ssl/certs by reading this file.
#
# This is autogenerated by dpkg-reconfigure ca-certificates.
# Certificates should be installed under /usr/share/ca-certificates
# and files with extension '.crt' is recognized as available certs.
#
# line begins with # is comment.
# line begins with ! is certificate filename to be deselected.
#
example.selfip.com.crt
brasil.gov.br/brasil.gov.br.crt
cacert.org/cacert.org.crt
cacert.org/class3.crt
.
.
.
-------------------------------------------------------------------------------
</pre></p>
<p>Execute the program &#8220;update-ca-certificates &#8211;fresh&#8221;.<br />
<strong>Note:</strong> You might like to backup /etc/ssl/certs before executing the command.<br />
<pre class="brush: bash;">
root@ubuntu:/etc# update-ca-certificates --fresh
Clearing symlinks in /etc/ssl/certs...done.
Updating certificates in /etc/ssl/certs....done.
Running hooks in /etc/ca-certificates/update.d....done.
</pre></p>
<p>Test with curl on your target HTTPS site and it should work now.<br />
<pre class="brush: bash;">
root@ubuntu:/etc# curl https://example.selfip.com
&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;
&lt;html&gt;&lt;head&gt;
.
.
.
</pre></p>
<p>Excellent References:<br />
<a class="alignleft" title="OpenSSL Command-Line HOWTO" href="http://www.madboa.com/geek/openssl/#verify-system" target="_blank">http://www.madboa.com/geek/openssl/#verify-system</a><br />
<a class="alignleft" title="Ubuntu Manpage: update-ca-certificates - update /etc/ssl/certs and certificates.crt" href="http://manpages.ubuntu.com/manpages/karmic/man8/update-ca-certificates.8.html" target="_blank">http://manpages.ubuntu.com/manpages/karmic/man8/update-ca-certificates.8.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/turboflash.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/turboflash.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/turboflash.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/turboflash.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/turboflash.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/turboflash.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/turboflash.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/turboflash.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/turboflash.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/turboflash.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/turboflash.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/turboflash.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/turboflash.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/turboflash.wordpress.com/203/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=203&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://turboflash.wordpress.com/2009/06/23/curl-adding-installing-trusting-new-self-signed-certificate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/439f31e58019ea93391bef3d7c8c352e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">turboflash</media:title>
		</media:content>
	</item>
		<item>
		<title>Zend Framework: Clearing/Resetting HeadLink, HeadMeta, HeadScript, HeadStyle and HeadTitle</title>
		<link>http://turboflash.wordpress.com/2009/02/07/zend-framework-clearing-resetting-headlink-headmeta-headscript-headstyle-and-headtitle/</link>
		<comments>http://turboflash.wordpress.com/2009/02/07/zend-framework-clearing-resetting-headlink-headmeta-headscript-headstyle-and-headtitle/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 04:00:00 +0000</pubDate>
		<dc:creator>turboflash</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Clear]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[HeadLink]]></category>
		<category><![CDATA[HeadMeta]]></category>
		<category><![CDATA[HeadScript]]></category>
		<category><![CDATA[HeadStyle]]></category>
		<category><![CDATA[HeadTitle]]></category>
		<category><![CDATA[Reset]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://turboflash.wordpress.com/?p=130</guid>
		<description><![CDATA[Scenario Assuming your application is running smoothly and all of the HeadX (Refers to HeadLink, HeadMeta, HeadScript, HeadStyle and HeadTitle collectively) have been setup. Suddenly, an exception occurs and your ErrorController has been activated. You need to use the HeadX to render your error page but those HeadX needs to be cleared of all the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=130&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Scenario</h2>
<p>Assuming your application is running smoothly and all of the HeadX (Refers to HeadLink, HeadMeta, HeadScript, HeadStyle and HeadTitle collectively) have been setup. Suddenly, an exception occurs and your <span style="font-family:Courier New;">ErrorController</span> has been activated.</p>
<p>You need to use the HeadX to render your error page but those HeadX needs to be cleared of all the previous unwanted setup before we can start using them to render the page. Somehow, there is no clear-related method in the HeadX to do this simply. If this situation, or somewhat related, applies to you, maybe the following article is for you.</p>
<h2>Some background</h2>
<p>You can <a href="#The_solution">skip</a> this part actually. But if you are interested in the technical details, you can continue reading. This post is written based on Zend Framework v1.7.4.</p>
<h4><span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Container_Standalone</span> class</h4>
<p>If you were to open up the <span style="font-family:Courier New;">Zend/View/Helper/HeadX.php</span>, you will find that those classes actually extend <span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Container_Standalone</span> class (We shall term it as Standalone class from now on).</p>
<p><pre class="brush: xml;">
Zend_View_Helper_Abstract (implements . . .)
 +- Zend_View_Helper_Placeholder_Container_Standalone (implements . . .)
     |- Zend_View_Helper_HeadLink
     |- Zend_View_Helper_HeadMeta
     |- Zend_View_Helper_HeadScript
     |- Zend_View_Helper_HeadStyle
     +- Zend_View_Helper_HeadTitle
</pre></p>
<p>In this Standalone class, there are a few protected variables that are of interest to us as follows.</p>
<ol>
<li><span style="font-family:Courier New;">$_container</span>: This variable holds a reference to an instance of <span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Container_Abstract</span> class, which essentially is an extended <span style="font-family:Courier New;">ArrayObject</span> class.
<p><a name="Zend_View_Helper_Placeholder_Container_Abstract" id="Zend_View_Helper_Placeholder_Container_Abstract"> </a><br />
<pre class="brush: xml;">
ArrayObject
 +- Zend_View_Helper_Placeholder_Container_Abstract
     +- Zend_View_Helper_Placeholder_Container
</pre>
    </li>
<li>$_registry: This variable holds a reference to an instance of <span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Registry</span> class, which is sort of a Singleton using <span style="font-family:Courier New;">Zend_Registry</span>.</li>
<li>$_regKey: This variable is overridden by each of the respective HeadX classes and is assigned a unique key, in this case, the class name itself. You can open up the individual <span style="font-family:Courier New;">Zend/View/Helper/HeadX.php</span> to find this key.</li>
</ol>
<p>I have extracted the relevant code from the Standalone class as follows. As you can see with reference to the above mentioned protected variables, the methods are actually quite simple and the important method here is <span style="font-family:Courier New;">__construct</span>. It is using a common placeholder registry to obtain a container reference for the respective HeadX class that we are using.</p>
<p>Using HeadLink as an example, you will find <span style="font-family:Courier New;">$_regKey</span> is assigned with the key &#8216;Zend_View_Helper_HeadLink&#8217; in <span style="font-family:Courier New;">Zend/View/Helper/HeadLink.php</span>. Essentially, this key will retrieve a unique common container reference purely used by the HeadLink class.</p>
<p><pre class="brush: php;">
public function __construct()
{
    $this-&gt;setRegistry(Zend_View_Helper_Placeholder_Registry::getRegistry());
    $this-&gt;setContainer($this-&gt;getRegistry()-&gt;getContainer($this-&gt;_regKey));
}

public function setRegistry(Zend_View_Helper_Placeholder_Registry $registry)
{
    $this-&gt;_registry = $registry;
    return $this;
}

public function getRegistry()
{
    return $this-&gt;_registry;
}

public function setContainer(Zend_View_Helper_Placeholder_Container_Abstract $container)
{
    $this-&gt;_container = $container;
    return $this;
}

public function getContainer()
{
    return $this-&gt;_container;
}
</pre></p>
<h4><span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Registry</span> class</h4>
<p>From <span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Registry</span> class, I have extracted the relevant code used by Standalone class constructor. As you can see, the <span style="font-family:Courier New;">$_regKey</span> in Standalone class is used to retrieve an unique instance of the container in <span style="font-family:Courier New;">getContainer</span> method. And if container is not created yet, a new instance will be created by <span style="font-family:Courier New;">createContainer</span> method. The container will be an instance of <a href="#Zend_View_Helper_Placeholder_Container_Abstract"><span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Container</span> which extends <span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Container_Abstract</span></a>.</p>
<p><pre class="brush: php;">
protected $_containerClass = 'Zend_View_Helper_Placeholder_Container';

public function getContainer($key)
{
    $key = (string) $key;
    if (isset($this-&gt;_items[$key])) {
        return $this-&gt;_items[$key];
    }

    $container = $this-&gt;createContainer($key);

    return $container;
}

public function createContainer($key, array $value = array())
{
    $key = (string) $key;

    $this-&gt;_items[$key] = new $this-&gt;_containerClass(array());
    return $this-&gt;_items[$key];
}
</pre></p>
<h4><span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Container</span> class</h4>
<p>At this point, we now know placeholder registry is the central repository for the containers and Standalone class retrieves the reference from it. We also know that the container is an instance of <span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Container</span> class, which exposes methods from both it&#8217;s <a href="#Zend_View_Helper_Placeholder_Container_Abstract"><span style="font-family:Courier New;">_Abstrast</span> parent class and <span style="font-family:Courier New;">ArrayObject</span> class</a>. </p>
<p>If you were to open up the <span style="font-family:Courier New;">Zend/View/Helper/HeadX.php</span> files, you will find that operations (such as <span style="font-family:Courier New;">append</span>, <span style="font-family:Courier New;">prepend</span>) on the container, returned by <span style="font-family:Courier New;">getContainer</span> method,  is performed using methods exposed by <span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Container</span> class.</p>
<p>However, inside <span style="font-family:Courier New;">Zend/View/Helper/HeadTitle.php</span>, you will find that it did not use <span style="font-family:Courier New;">getContainer</span> method at all and we are able to call <span style="font-family:Courier New;">set</span>, <span style="font-family:Courier New;">append</span> and <span style="font-family:Courier New;">prepend</span> on the instance of Standalone class itself, which does not have those methods. The trick to this is the following <span style="font-family:Courier New;">__call</span> method in the Standalone class, which indirectly exposes container methods as well.</p>
<p><pre class="brush: php;">
public function __call($method, $args)
{
    $container = $this-&gt;getContainer();
    if (method_exists($container, $method)) {
        $return = call_user_func_array(array($container, $method), $args);
        if ($return === $container) {
            // If the container is returned, we really want the current object
            return $this;
        }
        return $return;
    }

    require_once 'Zend/View/Exception.php';
    throw new Zend_View_Exception('Method &quot;' . $method . '&quot; does not exist');
}
</pre></p>
<p>So with the above <span style="font-family:Courier New;">__call</span> method, calling <span style="font-family:Courier New;">set</span>, <span style="font-family:Courier New;">append</span> and <span style="font-family:Courier New;">prepend</span> methods, which does not exist in Standalone class, will automatically route to the container inside. This will mean that all methods expose by <span style="font-family:Courier New;">Zend_View_Helper_Placeholder_Container_Abstract</span> and <span style="font-family:Courier New;">ArrayObject</span> can be invoked on Standalone class itself. </p>
<p><a name="The_solution" id="The solution"> </a></p>
<h2>The solution</h2>
<p>If you follow the technical stuff above, you will understand that the <span style="font-family:Courier New;">ArrayObject</span> methods are exposed on the HeadX classes as well. So to clear/reset HeadX, we just need the following line in <span style="font-family:Courier New;">.phtml</span> file. It&#8217;s just that simple. :) </p>
<p><pre class="brush: php;">
$this-&gt;headX()-&gt;exchangeArray(array())
</pre></p>
<p>You might like to read up on a related <a title="PHP - Clear/Delete/Remove operations on ArrayObject class &amp;laquo; Turboflash’s Blog" href="http://turboflash.wordpress.com/2009/02/07/php-clear-delete-remove-operations-on-arrayobject-class/" target="_blank">post</a> on clearing <span style="font-family:Courier New;">ArrayObject</span> for more information.</p>
<table>
<tr>
<td>
      <img src="http://turboflash.files.wordpress.com/2009/02/d.gif?w=480" alt="=D" title="=D"   class="alignnone size-full wp-image-77" />
    </td>
<td>
As usual, if you have any comments or if there is any better way of doing this, remember to share them with me.
    </td>
</tr>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/turboflash.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/turboflash.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/turboflash.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/turboflash.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/turboflash.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/turboflash.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/turboflash.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/turboflash.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/turboflash.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/turboflash.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/turboflash.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/turboflash.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/turboflash.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/turboflash.wordpress.com/130/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=130&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://turboflash.wordpress.com/2009/02/07/zend-framework-clearing-resetting-headlink-headmeta-headscript-headstyle-and-headtitle/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/439f31e58019ea93391bef3d7c8c352e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">turboflash</media:title>
		</media:content>

		<media:content url="http://turboflash.files.wordpress.com/2009/02/d.gif" medium="image">
			<media:title type="html">=D</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP: Clear/Delete/Remove operations on ArrayObject class</title>
		<link>http://turboflash.wordpress.com/2009/02/07/php-clear-delete-remove-operations-on-arrayobject-class/</link>
		<comments>http://turboflash.wordpress.com/2009/02/07/php-clear-delete-remove-operations-on-arrayobject-class/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 16:00:59 +0000</pubDate>
		<dc:creator>turboflash</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ArrayObject]]></category>
		<category><![CDATA[Clear]]></category>
		<category><![CDATA[Delete]]></category>
		<category><![CDATA[Remove]]></category>

		<guid isPermaLink="false">http://turboflash.wordpress.com/?p=99</guid>
		<description><![CDATA[There wasn&#8217;t much information available on the Internet by keyword searching on how to do clearing/deleting/removing operations on PHP ArrayObject class so I decided to contribute a small post on this topic and hopefully it will save some time for people researching on it. As of 7 February 2009, the PHP: ArrayObject &#8211; Manual did [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=99&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There wasn&#8217;t much information available on the Internet by keyword searching on how to do clearing/deleting/removing operations on PHP <span style="font-family:Courier New;">ArrayObject</span> class so I decided to contribute a small post on this topic and hopefully it will save some time for people researching on it.</p>
<p>As of 7 February 2009, the <a title="PHP - ArrayObject - Manual" href="http://www.php.net/manual/en/class.arrayobject.php" target="_blank">PHP: ArrayObject &#8211; Manual</a> did not document two very important methods in the class: <span style="font-family:Courier New;">exchangeArray()</span> and <span style="font-family:Courier New;">getArrayCopy()</span>. So I do agree with some post I came across that <span style="font-family:Courier New;">ArrayObject</span> in not very well documented and the methods should be included there.</p>
<p>Sunstorm Labs Blog has actually written a very interesting <a title="Sunstorm Labs Blog » What good are ArrayObjects?" href="http://www.sunstormlabs.net/blog/2008/02/29/what-good-are-arrayobjects/" target="_blank">article</a> on the topic of <span style="font-family:Courier New;">ArrayObject</span> so you might like to read it up. Some foundation here is actually based on that article and we will just concentrate on the operations mentioned in the title.</p>
<h2><span style="font-family:Courier New;">exchangeArray()</span> and <span style="font-family:Courier New;">getArrayCopy()</span> methods</h2>
<p>You can&#8217;t really apply <a title="PHP - Array Functions - Manual" href="http://www.php.net/manual/en/ref.array.php" target="_blank">array functions</a> directly on the <span style="font-family:Courier New;">ArrayObject</span> instance. In order to use them, you need to do it as follows.</p>
<p><pre class="brush: php;">
$arrayObject = new ArrayObject(array(1, 2, 3));
$array = $arrayObject-&gt;getArrayCopy();
$array = array_function($array);
$arrayObject-&gt;exchangeArray($array);
</pre></p>
<h2>Clearing <span style="font-family:Courier New;">ArrayObject</span></h2>
<p>This can be done using the following line. Simple and straight forward, isn&#8217;t it? :)</p>
<p><pre class="brush: php;">
$arrayObject-&gt;exchangeArray(array());
</pre></p>
<h2>Deleting/Removing value from <span style="font-family:Courier New;">ArrayObject</span></h2>
<p>This is where the <span style="font-family:Courier New;">exchangeArray()</span> and <span style="font-family:Courier New;">getArrayCopy()</span> methods come into action. We will apply <a title="PHP - array_splice - Manual" href="http://www.php.net/manual/en/function.array-splice.php" target="_blank"><span style="font-family:Courier New;">array_splice</span></a> function for the deleting/removal action.</p>
<p><pre class="brush: php;">
$arrayObject = new ArrayObject(array(1, 2, 3));
$array = $arrayObject-&gt;getArrayCopy();
array_splice($array, . . .);
$arrayObject-&gt;exchangeArray($array);
</pre></p>
<table>
<tr>
<td>
      <img src="http://turboflash.files.wordpress.com/2009/02/d.gif?w=480" alt="=D" title="=D"   class="alignnone size-full wp-image-77" />
    </td>
<td>
If there is any better way of doing this, remember to share them with me.
    </td>
</tr>
</table>
<p>Excellent References:<br />
<a class="alignleft" title="PHP - ArrayObject - Manual" href="http://www.php.net/manual/en/class.arrayobject.php" target="_blank">http://www.php.net/manual/en/class.arrayobject.php</a><br />
<a class="alignleft" title="SPL-StandardPHPLibrary - ArrayObject Class Reference" href="http://www.php.net/~helly/php/ext/spl/classArrayObject.html" target="_blank">http://www.php.net/~helly/php/ext/spl/classArrayObject.html</a><br />
<a class="alignleft" title="PHP - Arrays - Manual" href="http://www.php.net/manual/en/book.array.php" target="_blank">http://www.php.net/manual/en/book.array.php</a><br />
<a class="alignleft" title="Sunstorm Labs Blog » What good are ArrayObjects?" href="http://www.sunstormlabs.net/blog/2008/02/29/what-good-are-arrayobjects/" target="_blank">http://www.sunstormlabs.net/blog/2008/02/29/what-good-are-arrayobjects/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/turboflash.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/turboflash.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/turboflash.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/turboflash.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/turboflash.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/turboflash.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/turboflash.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/turboflash.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/turboflash.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/turboflash.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/turboflash.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/turboflash.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/turboflash.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/turboflash.wordpress.com/99/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=99&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://turboflash.wordpress.com/2009/02/07/php-clear-delete-remove-operations-on-arrayobject-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/439f31e58019ea93391bef3d7c8c352e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">turboflash</media:title>
		</media:content>

		<media:content url="http://turboflash.files.wordpress.com/2009/02/d.gif" medium="image">
			<media:title type="html">=D</media:title>
		</media:content>
	</item>
		<item>
		<title>Zend Framework: Extending Decorators Flexibility (Part 2)</title>
		<link>http://turboflash.wordpress.com/2009/02/05/zend-framework-extending-decorators-flexibility-part-2/</link>
		<comments>http://turboflash.wordpress.com/2009/02/05/zend-framework-extending-decorators-flexibility-part-2/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 04:00:20 +0000</pubDate>
		<dc:creator>turboflash</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Decorators]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://turboflash.wordpress.com/?p=50</guid>
		<description><![CDATA[In Part 1, we are able to split the content into parts and apply decorators on them separately. This can be achieved by using the following classes. I guess the render method of each class pretty much sums up what they do so I will not explain further. And finally, the App_Form_Decorator_Exception class for completeness. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=50&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://turboflash.wordpress.com/2009/02/05/zend-framework-extending-decorators-flexibility-part-1/">Part 1</a>, we are able to split the content into parts and apply decorators on them separately. This can be achieved by using the following classes. I guess the <span style="font-family:Courier New;">render</span> method of each class pretty much sums up what they do so I will not explain further.</p>
<p><pre class="brush: php;">
&lt;?php

/**
 * @see Zend_Form_Decorator_Abstract
 */
require_once 'Zend/Form/Decorator/Abstract.php';

/**
 * This class will store the content into this instance during rendering. You
 * can retrieve the stored content using the complementing class
 * App_Form_Decorator_Retrieve. When adding several instances of this decorator,
 * you will have to alias it. The alias given will be used as the name option of
 * the App_Form_Decorator_Retrieve decorator.
 *
 * Accepts the following option:
 * - clear: whether to clear the passed in content by returning an empty content.
 *
 * Add the following line to the init() function of the Zend_Form-extended class
 * and use 'Store' to instantiate this decorator class.
 *
 * $this-&gt;addPrefixPath('App_Form_Decorator', 'App/Form/Decorator', Zend_Form::DECORATOR);
 *
 * @category   App
 * @package    App_Form_Decorator
 */
class App_Form_Decorator_Store extends Zend_Form_Decorator_Abstract
{
    /**
     * @access protected
     * @var boolean
     */
    protected $_clear = null;
    /**
     * @access protected
     * @var string
     */
    protected $_content = null;

    /**
     * Specifies whether to clear the passed in content after it is stored in
     * this instance.
     *
     * @param  boolean  $clear  True if to clear the passed in content.
     * @return  App_Form_Decorator_Store  For method chaining.
     * @throws  App_Form_Decorator_Exception  If parameter is not valid.
     */
    public function setClear($clear)
    {
        if (!is_bool($clear))
        {
            require_once 'App/Form/Decorator/Exception.php';
            throw new App_Form_Decorator_Exception('Clear option is not defined');
        }

        $this-&gt;_clear = $clear;

        return $this;
    }

    /**
     * Returns whether to clear the passed in content after it is stored in
     * this instance.
     *
     * @return  boolean  True if to clear the passed in content.
     * @throws  App_Form_Decorator_Exception  If 'clear' option is not valid.
     */
    public function getClear()
    {
        if (is_null($this-&gt;_clear))
        {
            if (!is_null($clear = $this-&gt;getOption('clear')))
            {
                $this-&gt;setClear($clear);
                $this-&gt;removeOption('clear');
            }
            else
                $this-&gt;setClear(true);
        }

        return $this-&gt;_clear;
    }

    /**
     * Clears content stored in this instance.
     *
     * @return  App_Form_Decorator_Store  For method chaining.
     */
    public function clearContent()
    {
        $this-&gt;_content = null;

        return $this;
    }

    /**
     * Returns content stored in this instance.
     *
     * @param  boolean  $clear  True if to clear stored content in this instance.
     * @return  string  Stored content.
     */
    public function getContent($clear = false)
    {
        $content = $this-&gt;_content;

        if (is_null($content))
            $content = '';
        elseif ($clear)
            $this-&gt;clearContent();

        return $content;
    }

    /**
     * Store the passed in content for retrieval.
     *
     * @param  string  $content  Passed in content to store.
     * @return  string  Depending on the clear option, it is either empty content or as is.
     */
    public function render($content)
    {
        // Store the passed in content to this instance.
        $this-&gt;_content = $content;

        // Clear or return content.
        return ($this-&gt;getClear()) ? '' : $content;
    }
}
</pre></p>
<p><pre class="brush: php;">
&lt;?php

/**
 * @see Zend_Form_Decorator_Abstract
 */
require_once 'Zend/Form/Decorator/Abstract.php';

/**
 * This class will retrieve the stored content from complementing class
 * App_Form_Decorator_Store. When adding several instances of this decorator,
 * you will have to alias it. The alias is purely used to ensure the instances
 * will not overwrite each other. To retrieve the stored content, you will need
 * to pass the alias used in instantiating the App_Form_Decorator_Store
 * decorator to the 'name' option.
 *
 * Accepts the following options:
 * - name: The alias used when creating the App_Form_Decorator_Store instance.
 * - remove: Boolean value determining whether to remove the stored content
 *           after retrieval.
 * - separator: string with which to separate passed in content and retrieved
 *              content.
 * - placement: whether to append, prepend or replace with the retrieved
 *              content.
 *
 * Add the following line to the init() function of the Zend_Form-extended class
 * and use 'Retrieve' to instantiate this decorator class.
 *
 * $this-&gt;addPrefixPath('App_Form_Decorator', 'App/Form/Decorator', Zend_Form::DECORATOR);
 *
 * @category   App
 * @package    App_Form_Decorator
 */
class App_Form_Decorator_Retrieve extends Zend_Form_Decorator_Abstract
{
    /**
     * @access protected
     * @var string
     */
    protected $_name = null;
    /**
     * @access protected
     * @var boolean
     */
    protected $_remove = null;

    /**
     * Returns stored content from the App_Form_Decorator_Store instance.
     *
     * @param  boolean  $clear  True if to clear stored content after retrieval.
     * @return  string  Stored content.
     * @throws  App_Form_Decorator_Exception  If wrong decorator instance is retrieved.
     */
    protected function _getContent($clear)
    {
        $store = $this-&gt;getElement()-&gt;getDecorator($this-&gt;getName());

        if (!$store instanceof App_Form_Decorator_Store)
        {
            require_once 'App/Form/Decorator/Exception.php';
            throw new App_Form_Decorator_Exception('&quot;' . $this-&gt;getName() . '&quot; is not a App_Form_Decorator_Store decorator');
        }

        return $store-&gt;getContent($clear);
    }

    /**
     * Specifies the name/alias of the element decorator to retrieve.
     *
     * @param  string  $name  Name/alias of the element decorator to retrieve.
     * @return  App_Form_Decorator_Retrieve  For method chaining.
     * @throws  App_Form_Decorator_Exception  If parameter is not valid.
     */
    public function setName($name)
    {
        if (!is_string($name))
        {
            require_once 'App/Form/Decorator/Exception.php';
            throw new App_Form_Decorator_Exception('Element decorator name is not defined');
        }

        if (is_numeric($name))
        {
            require_once 'App/Form/Decorator/Exception.php';
            throw new App_Form_Decorator_Exception('Element decorator name must be alphanumeric');
        }

        $this-&gt;_name = $name;

        return $this;
    }

    /**
     * Returns name/alias of the element decorator to retrieve.
     *
     * @return  string  Name/alias of the element decorator to retrieve.
     * @throws  App_Form_Decorator_Exception  If 'name' option is not valid.
     */
    public function getName()
    {
        if (is_null($this-&gt;_name))
        {
            if (is_null($name = $this-&gt;getOption('name')))
            {
                require_once 'App/Form/Decorator/Exception.php';
                throw new App_Form_Decorator_Exception('Element decorator name is not defined in the options');
            }

            $this-&gt;setName($name);
            $this-&gt;removeOption('name');
        }

        return $this-&gt;_name;
    }

    /**
     * Specifies whether to remove the stored content in
     * App_Form_Decorator_Store instance after retrieval.
     *
     * @param  boolean  $remove  True if remove the stored content after retrieval.
     * @return  App_Form_Decorator_Store  For method chaining.
     * @throws  App_Form_Decorator_Exception  If parameter is not valid.
     */
    public function setRemove($remove)
    {
        if (!is_bool($remove))
        {
            require_once 'App/Form/Decorator/Exception.php';
            throw new App_Form_Decorator_Exception('Remove option is not defined');
        }

        $this-&gt;_remove = $remove;

        return $this;
    }

    /**
     * Returns whether to remove the stored content in
     * App_Form_Decorator_Store instance after retrieval.
     *
     * @return  boolean  True if remove the stored content after retrieval.
     * @throws  App_Form_Decorator_Exception  If 'remove' option is not valid.
     */
    public function getRemove()
    {
        if (is_null($this-&gt;_remove))
        {
            if (!is_null($remove = $this-&gt;getOption('remove')))
            {
                $this-&gt;setRemove($remove);
                $this-&gt;removeOption('remove');
            }
            else
                $this-&gt;setRemove(true);
        }

        return $this-&gt;_remove;
    }

    /**
     * Retrieves the stored content.
     *
     * @param  string  $content  Passed in content.
     * @return  string  Rendered content.
     */
    public function render($content)
    {
        switch ($this-&gt;getPlacement())
        {
            case self::APPEND:
                return $content . $this-&gt;getSeparator() . $this-&gt;_getContent($this-&gt;getRemove());

            case self::PREPEND:
                return $this-&gt;_getContent($this-&gt;getRemove()) . $this-&gt;getSeparator() . $content;

            default:
                return $this-&gt;_getContent($this-&gt;getRemove());
        }
    }
}
</pre></p>
<p>And finally, the <span style="font-family:Courier New;">App_Form_Decorator_Exception</span> class for completeness.</p>
<p><pre class="brush: php;">
&lt;?php

/**
 * @see Zend_Exception
 */
require_once 'Zend/Exception.php';

/**
 * @category   App
 * @package    App_Form_Decorator
 */
class App_Form_Decorator_Exception extends Zend_Exception
{
}
</pre></p>
<p>To use them, you just need to put these three classes into a folder <span style="font-family:Courier New;">App/Form/Decorator</span>. You need to add this folder to the <span style="font-family:Courier New;">include_path</span> similar to what you did for Zend library. Remember to enable autoloading using the <span style="font-family:Courier New;">Zend_Loader</span> class. Other information can be found in the class remarks.</p>
<table>
<tr>
<td>
      <img src="http://turboflash.files.wordpress.com/2009/02/d.gif?w=480" alt="=D" title="=D"   class="alignnone size-full wp-image-77" />
    </td>
<td>
If there is any optimization or bug, please feel free to point them out so that I can update my copy as well.
    </td>
</tr>
</table>
<table>
<tr>
<td>
      <img src="http://turboflash.files.wordpress.com/2009/02/oh.gif?w=480" alt="oh" title="oh"   class="alignnone size-full wp-image-78" />
    </td>
<td>
Oh&#8230; One more thing, you can also used the same concept to create decorator that does formatting, such as indentation, of the rendered content if you haven&#8217;t thought of that.
    </td>
</tr>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/turboflash.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/turboflash.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/turboflash.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/turboflash.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/turboflash.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/turboflash.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/turboflash.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/turboflash.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/turboflash.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/turboflash.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/turboflash.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/turboflash.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/turboflash.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/turboflash.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=50&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://turboflash.wordpress.com/2009/02/05/zend-framework-extending-decorators-flexibility-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/439f31e58019ea93391bef3d7c8c352e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">turboflash</media:title>
		</media:content>

		<media:content url="http://turboflash.files.wordpress.com/2009/02/d.gif" medium="image">
			<media:title type="html">=D</media:title>
		</media:content>

		<media:content url="http://turboflash.files.wordpress.com/2009/02/oh.gif" medium="image">
			<media:title type="html">oh</media:title>
		</media:content>
	</item>
		<item>
		<title>Zend Framework: Extending Decorators Flexibility (Part 1)</title>
		<link>http://turboflash.wordpress.com/2009/02/05/zend-framework-extending-decorators-flexibility-part-1/</link>
		<comments>http://turboflash.wordpress.com/2009/02/05/zend-framework-extending-decorators-flexibility-part-1/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 16:00:11 +0000</pubDate>
		<dc:creator>turboflash</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Decorators]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://http://turboflash.wordpress.com/?p=6</guid>
		<description><![CDATA[During form rendering, the decorators are executed in the order added and rendering are done on the same content throughout. If you were to open up Zend/Form.php, you will find inside an elegant render method as follows that summarizes what I&#8217;ve mentioned earlier. Here comes the issue. We cannot apply decorators selectively to a part [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=6&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>During form rendering, the decorators are executed in the order added and rendering are done on the same content throughout. If you were to open up <span style="font-family:Courier New;">Zend/Form.php</span>, you will find inside an elegant <span style="font-family:Courier New;">render</span> method as follows that summarizes what I&#8217;ve mentioned earlier.</p>
<p><pre class="brush: php;">
public function render(Zend_View_Interface $view = null)
{
    if (null !== $view) {
        $this-&gt;setView($view);
    }

    $content = '';
    foreach ($this-&gt;getDecorators() as $decorator) {
        $decorator-&gt;setElement($this);
        $content = $decorator-&gt;render($content);
    }
    return $content;
}
</pre></p>
<p>Here comes the issue. We cannot apply decorators selectively to a part of the content by breaking it up. You can only prepend, append or wrap the whole, not portion of, content with a new decorator. This poses a challenge if you need to create custom tags around both Label and Text Field in a <span style="font-family:Courier New;">Zend_Form_Element_Text</span> for example.</p>
<p>If you, like me, have been doing lots of research on Zend Form Decorators and is hitting the wall, I guess the following might be a solution that will give flexibility to the way decorators can be used. I hope this will help someone in a way or another.</p>
<p>Before I start presenting the possible solution, let me go through what we want to achieve, what we can achieve using the closest available method on the Internet and my proposed solution that introduces flexibility to what we want to achieve.</p>
<h2>What we want to achieve</h2>
<p>As an example, here&#8217;s what we want to achieve, a <span style="font-family:Courier New;">class</span> attribute of value <span style="font-family:Courier New;">label</span> for the first <span style="font-family:Courier New;">td</span> tag on line 2. This will allow us to style it with CSS class <span style="font-family:Courier New;">label</span>.</p>
<p><pre class="brush: xml;">
&lt;tr&gt;
    &lt;td class=&quot;label&quot;&gt;
        &lt;label for=&quot;username&quot; class=&quot;optional&quot;&gt;Username:&lt;/label&gt;
    &lt;/td&gt;
    &lt;td class=&quot;element&quot;&gt;
        &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;&quot; /&gt;
    &lt;/td&gt;
&lt;/tr&gt;
</pre></p>
<h2>What we can achieve using the closest available method</h2>
<p>Here are the decorators applied to <span style="font-family:Courier New;">Zend_Form_Element_Text</span> instance. On line 5, we have added an option <span style="font-family:Courier New;">&#8216;class&#8217; =&gt; &#8216;label&#8217;</span> to the <span style="font-family:Courier New;">Label</span> decorator.</p>
<p><pre class="brush: php;">
$element-&gt;setDecorators(array(
    'ViewHelper',
    'Errors',
    array(array('data' =&gt; 'HtmlTag'), array('tag' =&gt; 'td', 'class' =&gt; 'element')),
    array('Label', array('tag' =&gt; 'td', 'class' =&gt; 'label')),
    array(array('row' =&gt; 'HtmlTag'), array('tag' =&gt; 'tr')),
));
</pre></p>
<p>The following is achieved using the above code. As you can see, class <span style="font-family:Courier New;">label</span> is applied to <span style="font-family:Courier New;">label</span> tag on line 3, and not <span style="font-family:Courier New;">td</span> tag on line 2. This is not what we want.</p>
<p><pre class="brush: xml;">
&lt;tr&gt;
    &lt;td&gt;
        &lt;label for=&quot;username&quot; class=&quot;label optional&quot;&gt;Username:&lt;/label&gt;
    &lt;/td&gt;
    &lt;td class=&quot;element&quot;&gt;
        &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;&quot; /&gt;
    &lt;/td&gt;
&lt;/tr&gt;
</pre></p>
<h2>Proposed solution</h2>
<p>We will create two new decorator class: Store and Retrieve. It will be used as follows.</p>
<p><pre class="brush: php;">
$username-&gt;setDecorators(array(
    // Create element and store it.
    'ViewHelper',
    'Errors',
    array(array('td-element' =&gt; 'HtmlTag'), array('tag' =&gt; 'td', 'class' =&gt; 'element')),
    array(array('store-element' =&gt; 'Store'), array('clear' =&gt; true)),
    
    // Create label and store it.
    'Label',
    array(array('td-label' =&gt; 'HtmlTag'), array('tag' =&gt; 'td', 'class' =&gt; 'label')),
    array(array('store-label' =&gt; 'Store'), array('clear' =&gt; true)),
    
    // Retrieve both the label and element.
    array(array('retrieve-label' =&gt; 'Retrieve'), array('name' =&gt; 'store-label', 'remove' =&gt; true)),
    array(array('retrieve-element' =&gt; 'Retrieve'), array('name' =&gt; 'store-element', 'remove' =&gt; true)),
    
    // Wrap the retrieved label and element with tr tag.
    array(array('row' =&gt; 'HtmlTag'), array('tag' =&gt; 'tr')),
));
</pre></p>
<p>The following is achieved using the above code as what we have set out initially. We are now able to work on part of the content at a time.</p>
<p><pre class="brush: xml;">
&lt;tr&gt;
    &lt;td class=&quot;label&quot;&gt;
        &lt;label for=&quot;username&quot; class=&quot;optional&quot;&gt;Username:&lt;/label&gt;
    &lt;/td&gt;
    &lt;td class=&quot;element&quot;&gt;
        &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;&quot; /&gt;
    &lt;/td&gt;
&lt;/tr&gt;
</pre></p>
<p>In <a href="http://turboflash.wordpress.com/2009/02/05/zend-framework-extending-decorators-flexibility-part-2/">Part 2</a>, we will present the two newly derived decorator class.</p>
<p>Excellent References:<br />
<a class="alignleft" title="Zend Framework - Documentation" href="http://framework.zend.com/manual/en/zend.form.standardDecorators.html" target="_blank">http://framework.zend.com/manual/en/zend.form.standardDecorators.html</a><br />
<a class="alignleft" title="Decorators with Zend_Form" href="http://devzone.zend.com/article/3450-Decorators-with-Zend_Form" target="_blank">http://devzone.zend.com/article/3450-Decorators-with-Zend_Form</a><br />
<a class="alignleft" title="Zend Form Decorators &laquo; Zend Framework" href="http://zendguru.wordpress.com/2008/10/23/zend-form-decorators/" target="_blank">http://zendguru.wordpress.com/2008/10/23/zend-form-decorators/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/turboflash.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/turboflash.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/turboflash.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/turboflash.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/turboflash.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/turboflash.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/turboflash.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/turboflash.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/turboflash.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/turboflash.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/turboflash.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/turboflash.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/turboflash.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/turboflash.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=turboflash.wordpress.com&amp;blog=6445287&amp;post=6&amp;subd=turboflash&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://turboflash.wordpress.com/2009/02/05/zend-framework-extending-decorators-flexibility-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/439f31e58019ea93391bef3d7c8c352e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">turboflash</media:title>
		</media:content>
	</item>
	</channel>
</rss>
