<?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; axial</title>
	<atom:link href="http://www.phpaddiction.com/tags/category/axial/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>
		<item>
		<title>Url Routing with PHP &#8211; Part One</title>
		<link>http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/</link>
		<comments>http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/#comments</comments>
		<pubDate>Tue, 27 Mar 2007 17:38:07 +0000</pubDate>
		<dc:creator>Doug Hill</dc:creator>
				<category><![CDATA[axial]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[url routing]]></category>

		<guid isPermaLink="false">http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/</guid>
		<description><![CDATA[Most PHP frameworks use some variation of the front controller pattern to centralize common code and logic.  There are advantages and disadvantages to this.  I am going to ignore those for now. In fact the first part of this series  will explore a simple procedural <abbr title ="Universal Resourse Locator. A type of Universal Resource Identifier.">URL</abbr> routing method that contains many of the disadvantages. In later articles we will build upon this basis and address the disadvantages.]]></description>
			<content:encoded><![CDATA[<p>Most PHP frameworks use some variation of the front controller pattern to centralize common code and logic.  There are advantages and disadvantages to this.  I am going to ignore those for now. In fact the first part of this series  will explore a simple procedural <abbr title ="Universal Resourse Locator. A type of Universal Resource Identifier.">URL</abbr> routing method that contains many of the disadvantages. In later articles we will build upon this basis and address the disadvantages.<br />
<span id="more-7"></span></p>
<h3>Requirements</h3>
<ul style="margin-top:10px;">
<li>PHP</li>
<li>Apache with mod_rewrite enabled.</li>
</ul>
<h3>Redirecting with mod_rewrite</h3>
<p>This article doesn't discuss mod_rewrite and the .htaccess in detail, the following .htaccess file is sufficient for the needs of our simple front controller. The .htaccess file should be placed in the same directory as the front controller script. All requests will be sent to index.php while requests for a file or directory that <em>does exist</em> will bypass the mod_rewrite rules and be served directly by the web server.</p>
<p>file: .htaccess</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">Options</span> +<span class="kw2">FollowSymLinks</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">IndexIgnore</span> */*</div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># Turn on the RewriteEngine</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">RewriteEngine</span> <span class="kw2">On</span></div>
</li>
<li class="li2">
<div class="de2"><span class="co1"># &nbsp;Rules</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>REQUEST_FILENAME<span class="br0">&#125;</span> !-f </div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>REQUEST_FILENAME<span class="br0">&#125;</span> !-d</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">RewriteRule</span> . index.php</div>
</li>
</ol>
</div>
<h3>The Entry Point</h3>
<p>I chose a simple format for the incoming <abbr title ="Universal Resourse Locator. A type of Universal Resource Identifier.">URL</abbr>, a command followed by its parameters separated by forward slashes "/".</p>
<p>For example:<br />
<span style="color:blue;font-weight:bold;">www.example.com/command/parameter1/parameter2/</span></p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$requestURI</span> = <a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">&#40;</span><span class="st0">'/'</span>, <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">'REQUEST_URI'</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>in this example $requestURI would contain.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/array"><span class="kw3">Array</span></a> <span class="br0">&#40;</span> <span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> =&gt; <span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> =&gt; command <span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span> =&gt; parameter1 <span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span> =&gt; parameter2 <span class="br0">&#91;</span><span class="nu0">4</span><span class="br0">&#93;</span> =&gt; <span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>This works fine except in the case where the front controller is not in the root directory.</p>
<p>For example:<br />
<span style="color:blue;font-weight:bold;">www.example.com/myapps/app1/command/parameter1/parameter2/</span></p>
<p>in this case $requestURI would contain.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/array"><span class="kw3">Array</span></a> <span class="br0">&#40;</span> <span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> =&gt; <span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> =&gt; myapps <span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span> =&gt; app1 <span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span> =&gt; command <span class="br0">&#91;</span><span class="nu0">4</span><span class="br0">&#93;</span> =&gt; parameter1 <span class="br0">&#91;</span><span class="nu0">5</span><span class="br0">&#93;</span> =&gt; parameter2 &nbsp;<span class="br0">&#91;</span><span class="nu0">6</span><span class="br0">&#93;</span> =&gt; <span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>To filter out the path to the front controller we will need to use the $_SERVER['SCRIPT_NAME'] variable.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$requestURI</span> = <a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">&#40;</span><span class="st0">'/'</span>, <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">'REQUEST_URI'</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$scriptName</span> = <a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">&#40;</span><span class="st0">'/'</span>,<span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">'SCRIPT_NAME'</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>In the above example $scriptName would contain.</p>
<pre>Array ( [0] => [1] => myapps[2] => app1 [3] => index.php )</pre>
<p>Which can be used to remove the path and script name from the URI.<br />
<span style="font-size:.8em;font-style:italic;"><span style="font-weight:bold;">Note:</span>&nbsp;As you can see the explode method leaves an empty array member at the first position. This will be fixed by the following code.</span></p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$requestURI</span> = <a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">&#40;</span><span class="st0">'/'</span>, <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">'REQUEST_URI'</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$scriptName</span> = <a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">&#40;</span><span class="st0">'/'</span>,<span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">'SCRIPT_NAME'</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span><span class="br0">&#40;</span><span class="re0">$i</span>= <span class="nu0">0</span>;<span class="re0">$i</span> &lt; <a href="http://www.php.net/sizeof"><span class="kw3">sizeof</span></a><span class="br0">&#40;</span><span class="re0">$scriptName</span><span class="br0">&#41;</span>;<span class="re0">$i</span>++<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$requestURI</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span>&nbsp; &nbsp; &nbsp;== <span class="re0">$scriptName</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/unset"><span class="kw3">unset</span></a><span class="br0">&#40;</span><span class="re0">$requestURI</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$command</span> = <a href="http://www.php.net/array_values"><span class="kw3">array_values</span></a><span class="br0">&#40;</span><span class="re0">$requestURI</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>After the code above $command would contain.</p>
<pre>Array ( [0] => command [1] => parameter1 [2] => parameter2  [3] => )</pre>
<h3>Dispatching the command</h3>
<p>Now that we have a command with its parameters stored in an array it is trivial to handle them via a switch statement.  The following is a short example.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">switch</span><span class="br0">&#40;</span><span class="re0">$command</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">'commandOne'</span> : </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">'You entered command: '</span>.<span class="re0">$command</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">'commandTwo'</span> : </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">'You entered command: '</span>.<span class="re0">$command</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw2">default</span>: </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">'That command does not exist.'</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<h3>Try it out</h3>
<p>You can visit <a href="http://examples.phpaddiction.com/urlrouter/part_1/">examples.phpaddiction.com/urlrouter/part_1/</a> to see it in action and download the sample code.</p>
<h3>Next up</h3>
<p>The next part in the series will focus on moving the <abbr title ="Universal Resourse Locator. A type of Universal Resource Identifier.">URL</abbr> router into a class and out of the global namespace.</p>
<p><b>Update</b> I've updated the .htaccess per the comment made by DrBacchus.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Yet another PHP framework</title>
		<link>http://www.phpaddiction.com/tags/axial/yet-another-php-framework/</link>
		<comments>http://www.phpaddiction.com/tags/axial/yet-another-php-framework/#comments</comments>
		<pubDate>Tue, 13 Mar 2007 09:13:15 +0000</pubDate>
		<dc:creator>Doug Hill</dc:creator>
				<category><![CDATA[axial]]></category>

		<guid isPermaLink="false">http://www.phpaddiction.com/tags/axial/php-addiction-and-yet-another-framework/</guid>
		<description><![CDATA[Call it NIH, re-inventing the wheel, narcissism, or any number of other terms that come to mind, but Iâ€™ve always wanted to write my own PHP framework. Simple time constraints usually stop this self destructive urge in its tracks, but Iâ€™ve decided that Iâ€™m tired of saying to myself â€œFramework PHPxyz would be great if only it had ABC.â€. So it is time to Just Do It.]]></description>
			<content:encoded><![CDATA[<p>Call it <abbr title="Not Invented Here">NIH</abbr>, re-inventing the wheel, narcissism, or any number of other terms that come to mind, but I've always wanted to write my own PHP framework. Simple time constraints usually stop this self destructive urge in its tracks, but I've decided that I'm tired of saying to myself "Framework PHPxyz would be great if only it had ABC.". So it is time to <em>Just Do It</em>.</p>
<p>No matter how much this project screams ego, my real objective is to learn and share with my fellow PHP addicts. I intend to chronicle the project here on phpaddiction.com as part of an experimental development process. I haven't thought of a buzzword for this process yet but you know its coming! All egomaniacs who impose new frameworks on the world instead of working on an existing one must coin new buzzwords to help justify their pet project and I don't intend to be left out.</p>
<p>Oh and hopefully we all learn something too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpaddiction.com/tags/axial/yet-another-php-framework/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
