<?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/"
	>

<channel>
	<title>phpaddiction &#187; configuration</title>
	<atom:link href="http://www.phpaddiction.com/tags/category/configuration/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpaddiction.com</link>
	<description></description>
	<lastBuildDate>Wed, 23 Sep 2009 19:08:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP Application Configuration with YAML</title>
		<link>http://www.phpaddiction.com/tags/axial/php-application-configuration-with-yaml/</link>
		<comments>http://www.phpaddiction.com/tags/axial/php-application-configuration-with-yaml/#comments</comments>
		<pubDate>Thu, 22 Nov 2007 12:00:30 +0000</pubDate>
		<dc:creator>Doug Hill</dc:creator>
				<category><![CDATA[axial]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://www.phpaddiction.com/tags/axial/php-application-configuration-with-yaml/</guid>
		<description><![CDATA[<p>I have always disliked creating configuration data by reading from various formats into global arrays, so I needed to build or borrow a configuration class for my own projects that I could standardize on. </p>

<p>I wanted the following functionality.
<ul>
<li>Use the YAML format</li>
<li>Minimize load time by caching configuration data</li>
<li>Use object notation instead of array access notation.</li>
</ul>
</p>

<p>I discovered various configuration classes but none of them quite had everything I was looking for so I put together the best code and ideas (for my purposes) that I found to create the Axial_Configuration class.</p>]]></description>
			<content:encoded><![CDATA[<p>I have always disliked creating configuration data by reading from various formats into global arrays, so I needed to build or borrow a configuration class for my own projects that I could standardize on. </p>
<p><span id="more-13"></span></p>
<p>I wanted the following functionality.</p>
<ul>
<li>Use the YAML format</li>
<li>Minimize load time by caching configuration data</li>
<li>Use object notation instead of array access notation.</li>
</ul>
<p>I discovered various configuration classes but none of them quite had everything I was looking for so I put together the best code and ideas (for my purposes) that I found to create the Axial_Configuration class.</p>
<h3>The Base</h3>
<p>During my search for a configuration class I discovered the Zend_Config class which is a perfect fit as far as my object notation requirements. However Zend_Config lacks a YAML implementation and has no cache functionality.  I decided to base my class on the Zend_Config ideas to achieve the object notation functionality and added on YAML and cache support.</p>
<h3>The YAML format</h3>
<p>If you are unfamiliar with the YAML format you probably want to read the following. I won't go into the specifics as they are covered in depth elsewhere.</p>
<ul>
<li><a href="http://sourceforge.net/projects/spyc/">http://sourceforge.net/projects/spyc/</a></li>
<li><a href="http://www.yaml.org">http://www.yaml.org</a></li>
<li><a href="http://www.yaml.org/spec/">http://www.yaml.org/spec/</a></li>
<li><a href="http://yaml.kwiki.org/?YamlInFiveMinutes">http://yaml.kwiki.org/?YamlInFiveMinutes</a></li>
<li><a href="http://www.whytheluckystiff.net/syck/">http://www.whytheluckystiff.net/syck/</a></li>
</ul>
<p>I discovered YAML while doing some research into various PHP configuration formats a while back and immediately clicked with it.  I found two YAML parsers for PHP  <a href="http://spyc.sourceforge.net/">Spyc a simple php yaml class</a> and the <a href="http://www.whytheluckystiff.net/syck/">Syck extension</a>.  Most of my development is done with shared hosting in mind so the Syck extension isn't an option for now.</p>
<h3>Make it Faster</h3>
<p>Since loading and parsing YAML in PHP is not the fastest operation I would love to use the <a href="http://www.whytheluckystiff.net/syck/">Syck extension</a> but in order to ensure compatibility in a variety of environments I implemented a caching scheme using var_export() and the magic method __set_state(). Testing shows a load time decrease of about 30x to 50x for cached data.</p>
<h3>Try it out</h3>
<p>I know there are dozens of other configuration classes out there but hey "variety is the spice of life. &#8212; <a href="http://en.wikipedia.org/wiki/William_Cowper" >William Cowper</a>. I don't have much in documentation for it but here is a little bit of code to show you basic usage.
</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//create an instance that is read only and cached in the current directory.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//you will need to make sure that the directory is writeable.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="re0">$config</span> = <span class="kw2">new</span> Axial_Configuration_Yaml<span class="br0">&#40;</span><span class="st0">'config.yaml'</span>,<span class="kw2">true</span>,<span class="st0">'./'</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">'File: '</span>.<span class="re0">$config</span>-&gt;<span class="me1">file</span> . <span class="st0">'.&lt;br/&gt;'</span>;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">'Purpose: '</span>.<span class="re0">$config</span>-&gt;<span class="me1">purpose</span> . <span class="st0">'.&lt;br/&gt;'</span>;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">'Data: '</span>.<a href="http://www.php.net/print_r"><span class="kw3">print_r</span></a><span class="br0">&#40;</span><span class="re0">$config</span>-&gt;<span class="me1">data</span>-&gt;<span class="me1">toArray</span><span class="br0">&#40;</span><span class="br0">&#41;</span>,<span class="kw2">true</span><span class="br0">&#41;</span> . <span class="st0">'.&lt;br/&gt;'</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<h3>Requirements</h3>
<ul>
<li>PHP 5.1+</li>
</ul>
<p>You can <a href="http://www.phpaddiction.com/examples/downloads/configuration/axial.configuration.yaml.zip">download the code</a> and try it out. Let me know if you find it useful ¦ or not.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpaddiction.com/tags/axial/php-application-configuration-with-yaml/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
