<?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>Eivind E. Valderhaug &#187; Software development</title>
	<atom:link href="http://eivind.dataweb.no/?feed=rss2&#038;cat=8" rel="self" type="application/rss+xml" />
	<link>http://eivind.dataweb.no</link>
	<description>geek stuff</description>
	<lastBuildDate>Mon, 16 Mar 2009 14:32:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Handling templates with output buffering</title>
		<link>http://eivind.dataweb.no/?p=11</link>
		<comments>http://eivind.dataweb.no/?p=11#comments</comments>
		<pubDate>Mon, 17 Dec 2007 00:40:32 +0000</pubDate>
		<dc:creator>Eivind</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[output buffering]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://eivind.dataweb.no/?p=11</guid>
		<description><![CDATA[I just read a blog entry by Arnold Daniels about handling templates in PHP using output buffering with a callback function. I&#8217;ve previously used a somewhat similar approach to templating using output buffering and register_shutdown_function, but using a callback function when starting output buffering is an interesting concept I hadn&#8217;t thought of so I had [...]]]></description>
			<content:encoded><![CDATA[<p>I just read a <a href="http://blog.adaniels.nl/articles/how-i-php-the-output-handler/">blog entry</a> by Arnold Daniels about handling templates in PHP using output buffering with a callback function.</p>
<p>I&#8217;ve previously used a somewhat similar approach to templating using <a href="http://php.net/ref.outcontrol">output buffering</a> and <a href="http://php.net/register_shutdown_function">register_shutdown_function</a>, but using a callback function when starting output buffering is an interesting concept I hadn&#8217;t thought of so I had to look into it.</p>
<p>I found his solution a little lacking, so I created my own version of it. After I had created my own version though, I read a <a href="http://blog.adaniels.nl/articles/how-i-php-the-output-handler-continued/">follow-up article</a> on the same blog with an improved version of his solution. It turned out that my version was almost identical to the version in the follow-up article (even to the point that we both implemented static methods/members which the first article didn&#8217;t do). I guess great minds really do think alike. <img src='http://eivind.dataweb.no/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The differences between mine and his are basically too few and unimportant to justify me blogging about it, but it&#8217;s a little late for that now.. I found his second article after doing some more research after I had started writing this post, and I might as well finish it now. I&#8217;ll be short though.</p>
<p>My version</p>
<ul>
<li>implements the <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a></li>
<li>have header and footer as separate options</li>
<li>does not implement the mark/endmark methods introduced in Daniels second version (which I&#8217;ve found no need for)</li>
</ul>
<p>Anyway, here it is, with a very simple usage example.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> OutputHandler
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$instance</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$header</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$footer</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$templateVars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __construct <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
	final <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __clone<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$instance</span> instanceof <span style="color: #000000; font-weight: bold;">self</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$instance</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">func_get_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$footer</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'callback'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$instance</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> callback <span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #339933;">,</span> <span style="color: #000088;">$flags</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$flags</span> <span style="color: #339933;">&amp;</span> <span style="color: #009900; font-weight: bold;">PHP_OUTPUT_HANDLER_END</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">parseTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">parseTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">parseTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$footer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000000; font-weight: bold;">function</span> parseTemplate <span style="color: #009900;">&#40;</span><span style="color: #000088;">$template</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$templateVars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$templateVars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$template</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> setTemplateVar <span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$templateVars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
OutputHandler<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header.phtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'footer.phtml'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
OutputHandler<span style="color: #339933;">::</span><span style="color: #004000;">setTemplateVar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;!-- Title --&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Page title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
OutputHandler<span style="color: #339933;">::</span><span style="color: #004000;">setTemplateVar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;!-- The list --&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;ENDOUTPUT
&lt;ul&gt;
	&lt;li&gt;Item 1&lt;/li&gt;
	&lt;li&gt;Item 2&lt;/li&gt;
&lt;/ul&gt;
ENDOUTPUT</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;Content, content, content!&lt;/p&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;Before the list&lt;/p&gt;
	&lt;!-- The list --&gt;
	&lt;p&gt;After the list&lt;/p&gt;'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>When the script ends the above echo&#8217;ed lines will be output within the header and footer templates. The above echo&#8217;ed string &#8220;&lt;!&#8211; The list &#8211;&gt;&#8221; will be replaced with the unordered list defined with OutputHandler::setTemplateVar() and if the string &#8220;&lt;!&#8211; Title &#8211;&gt;&#8221; is found anywhere, including the header or footer templates, it will be replaced with &#8220;Page title&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://eivind.dataweb.no/?feed=rss2&amp;p=11</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set include path for Zend Framework</title>
		<link>http://eivind.dataweb.no/?p=8</link>
		<comments>http://eivind.dataweb.no/?p=8#comments</comments>
		<pubDate>Thu, 13 Dec 2007 13:48:16 +0000</pubDate>
		<dc:creator>Eivind</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://eivind.dataweb.no/?p=8</guid>
		<description><![CDATA[When using Zend Framework, its library must be present in the PHP directive &#8216;include_path&#8216;, so a common thing to do when using ZF is to set the include_path inside the app and include a directory where the ZF library is supposed to be installed. Here&#8217;s my problem: Instead of hard-coding a path to a directory [...]]]></description>
			<content:encoded><![CDATA[<p>When using <a href="http://framework.zend.com/" title="Zend Framework">Zend Framework</a>, its library must be present in the PHP directive &#8216;<a href="http://www.php.net/manual/en/ini.core.php#ini.include-path" title="include_path">include_path</a>&#8216;, so a common thing to do when using ZF is to set the include_path inside the app and include a directory where the ZF library is supposed to be installed.</p>
<p>Here&#8217;s my problem: Instead of hard-coding a path to a directory that may or may not contain the framework, I wanted a simple way to configure include_path without having to override the global setting through php.ini, .htaccess, etc. Naturally I can&#8217;t use <a href="http://framework.zend.com/manual/en/zend.config.html" title="Zend_Config">Zend_Config</a> which I&#8217;d otherwise use for configurations.</p>
<p>The directory structure I&#8217;m using is based on the structure suggested in the tutorial <a href="http://akrabat.com/zend-framework-tutorial/">Getting Started with the Zend Framework</a> by Rob Allen. This means that I have 3 directories in the application root directory, &#8216;app&#8217; for application files, &#8216;lib&#8217; for libraries (such as Zend Framework) and &#8216;pub&#8217; for public files (css, js, images, etc). I could just ship my application with a copy of Zend Framework inside the lib-directory and leave it at that, but I don&#8217;t want that since people may already have a copy of the framework on their servers and may not want another copy for storage reasons or just simplicity.</p>
<p>The solution I came up with was to create simple text-files in my applications lib-directory containing paths to include in include_path. My app would then scan this directory and extract the contents of all files matching a given extension before setting include_path using these extracted values. The extension I went with for these simple config-files was &#8216;.libp&#8217;, short for &#8216;lib-path&#8217;.</p>
<p>In my application object constructor, I now have</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DS'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PS'</span><span style="color: #339933;">,</span> PATH_SEPARATOR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AR'</span><span style="color: #339933;">,</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/..'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># application root
</span>
try
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span>_set_include_path<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!@</span><span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend/Loader.php'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Failed to load Zend Framework. This is a required library and must be installed.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I think the code is fairly obvious, so I won&#8217;t waste time commenting it further.</p>
<p>Later in the same class, I have these methods</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000000; font-weight: bold;">function</span> _set_include_path <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$customLibPaths</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$libPath</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lib'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;"># filter out non-regular files, files starting with a punctuation mark and files not ending with .libp
</span>	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">scandir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$libPath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$file'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return (strpos($file, \'.\') === 0 || !is_file(\''</span> <span style="color: #339933;">.</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$libPath</span> <span style="color: #339933;">.</span> DS<span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\' . $file) || pathinfo($file, PATHINFO_EXTENSION) !== \'libp\' ? false : true);'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$tmpPath</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$libPath</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpPath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmpPath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&quot;%s&quot; is not an existing directory, please change %s to contain a real include path. If you don\'t want to set a new include path in this file, you may either delete it or empty it.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmpPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$libPath</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$customLibPaths</span> <span style="color: #339933;">.=</span> PS <span style="color: #339933;">.</span> <span style="color: #000088;">$tmpPath</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span>
		AR
		<span style="color: #339933;">.</span> PS <span style="color: #339933;">.</span> AR <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #0000ff;">'lib'</span>
		<span style="color: #339933;">.</span> <span style="color: #000088;">$customLibPaths</span>
		<span style="color: #339933;">.</span> PS <span style="color: #339933;">.</span> <span style="color: #990000;">get_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Get absolute path to a directory or file by passing any number of path entities (directories/files) relative from the application root
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getPath <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">func_get_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># Can't be used as a function parameter directly, must be assigned to a variable
</span>	<span style="color: #b1b100;">return</span> AR <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span>DS<span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The lib-directory contains files such as zend-framework.libp, holding a simple string each with the path to the respective libraries. When trying to include files, PHP will now first check the application root, then the lib directory, any custom lib-paths and finally the default include_path.</p>
<p>If I ever want to implement some sort of plugin system for my app, any plugins relying on external libraries may add a file in the lib-directory to configure the include path instead of modifying main application files. I can also use this myself of course if I at a later point want to make use of further third party libraries and allow end-users to easily configure the paths to those libraries.</p>
]]></content:encoded>
			<wfw:commentRss>http://eivind.dataweb.no/?feed=rss2&amp;p=8</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trac 0.11 beta coming soon</title>
		<link>http://eivind.dataweb.no/?p=6</link>
		<comments>http://eivind.dataweb.no/?p=6#comments</comments>
		<pubDate>Sat, 08 Dec 2007 03:00:08 +0000</pubDate>
		<dc:creator>Eivind</dc:creator>
				<category><![CDATA[Software development]]></category>

		<guid isPermaLink="false">http://eivind.dataweb.no/?p=6</guid>
		<description><![CDATA[In case you didn&#8217;t know, Trac is an open source software project management tool. According to the Trac roadmap, they&#8217;re about to release a beta version of the long-awaited 0.11 release. On that occasion, they ask that people help them make a fool-proof release by downloading and testing the latest revision (trunk) from the subversion [...]]]></description>
			<content:encoded><![CDATA[<p>In case you didn&#8217;t know, <a href="http://trac.edgewall.org">Trac</a> is an open source software project management tool.</p>
<p>According to the <a href="http://trac.edgewall.org/roadmap">Trac roadmap</a>, they&#8217;re about to release a beta version of the long-awaited 0.11 release. On that occasion, they ask that people help them make a fool-proof release by downloading and testing the latest revision (trunk) from the subversion repository.</p>
<p>The 0.11 release has been in development for over a year now and it closes more than 400 tickets in their issue tracker. Most issues were defects but there are also several enhancements. Some of the highlights are the integrated web-admin plugin, configurable workflow and easier installation procedure. See the <a href="http://trac.edgewall.org/wiki/TracDev/ReleaseNotes/0.11">release notes for 0.11</a> in the Trac wiki for much more info on what&#8217;s new. I installed the latest trunk yesterday, and so far it looks really good. Even for a one-man private project, this is a tool that makes a difference.</p>
]]></content:encoded>
			<wfw:commentRss>http://eivind.dataweb.no/?feed=rss2&amp;p=6</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Data Manager &#8211; PHP ETL?</title>
		<link>http://eivind.dataweb.no/?p=3</link>
		<comments>http://eivind.dataweb.no/?p=3#comments</comments>
		<pubDate>Sun, 25 Nov 2007 19:33:09 +0000</pubDate>
		<dc:creator>Eivind</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Data Manager]]></category>
		<category><![CDATA[ETL]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://dataweb.s8.subsys.net/blog/?p=3</guid>
		<description><![CDATA[Project Data Manager was started in march 2005, and in the beginning it was intended to be an add-on for Zen Cart, a shopping cart system in PHP. At the beginning of the project I was just starting out in the world of programming and PHP, and the project has been my own programming training [...]]]></description>
			<content:encoded><![CDATA[<p>Project <a href="http://datamanager.no">Data Manager</a> was started in march 2005, and in the beginning it was intended to be an add-on for <a href="http://zen-cart.com">Zen Cart</a>, a shopping cart system in PHP. At the beginning of the project I was just starting out in the world of programming and PHP, and the project has been my own programming training course, so to speak. Development has been periodically sporadic, due to interest and time.</p>
<p>I&#8217;ve dedicated enormous amounts of time and energy into this project, but will it ever become ready for a public release or will it forever remain only on my personal computer as a programming exercise?<br />
<span id="more-3"></span><br />
The project goals have changed several times since the beginning and the code has gone through multiple refactorings whenever I learned something new and important. Some time during the fall -06, I wanted it to become more of a general purpose data handling tool, not only for Zen Cart but for almost any solution. Then in spring -07 I decided it should become more of an ETL (Extract, Transform, Load) tool. At that time I also wanted to create a lightweight solution targeted at Zen Cart, and I almost completed it too! (Amazing, finally I -almost- had something to release!)</p>
<p>Then life got in the way. I got a girlfriend, moved in with her, got a new job, then we moved to another city and I got another new job. Since then I&#8217;ve lost interest in Zen Cart and have lately been looking at <a href="http://magentocommerce.com">Magento</a>, which in my opinion looks much, much better. Currently I&#8217;m in the middle of yet another code refactoring, this time applying the MVC pattern to my application using <a href="http://framework.zend.com">Zend Framework</a>.</p>
<p>The reason behind the changing goals is simply that I have been following my own changing needs and desire to learn programming and PHP, instead of committing to a community need. The future of the project is currently still unclear, but hopefully there will be a Data Manager 1.0 eventually. Don&#8217;t hold your breath though, at this point I won&#8217;t guarantee anything. If you haven&#8217;t already, be sure to check out <a href="http://www.talend.com/products-data-integration/talend-open-studio.php">Talend Open Studio</a>, assuming of course that you&#8217;re in need of an ETL tool.</p>
]]></content:encoded>
			<wfw:commentRss>http://eivind.dataweb.no/?feed=rss2&amp;p=3</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
