<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<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/"
	>

<channel>
	<title>Eirik Hoem's Blog</title>
	<link>http://blog.eirikhoem.net</link>
	<description>Mainly PHP</description>
	<pubDate>Mon, 23 Jun 2008 10:58:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Simple config management for PHP</title>
		<link>http://blog.eirikhoem.net/index.php/2008/05/30/simple-config-management-for-php/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/05/30/simple-config-management-for-php/#comments</comments>
		<pubDate>Fri, 30 May 2008 07:30:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/05/30/simple-config-management-for-php/</guid>
		<description><![CDATA[When doing complex applications it&#8217;s often nice to have some sort of system for handling settings. PHP has a nice function called parse_ini_file which can be used to create a basic but still usable setting file feature. A simple class which loads the configuration file and offers some methods to retrieve the values for a [...]]]></description>
			<content:encoded><![CDATA[<p>When doing complex applications it&#8217;s often nice to have some sort of system for handling settings. PHP has a nice function called <a href="http://no2.php.net/parse_ini_file" onclick="javascript:pageTracker._trackPageview ('/outbound/no2.php.net');">parse_ini_file</a> which can be used to create a basic but still usable setting file feature. A simple class which loads the configuration file and offers some methods to retrieve the values for a given key is all that&#8217;s needed. The example I&#8217;m providing is pretty basic, but it&#8217;s still very usable and can be added to almost any application.</p>
<p>First, we need to create a file to hold the settings. It&#8217;s ordinary plaintext and follows the INI format.</p>
<p><strong> Here is a quick sample of some key / value pairs:</strong></p>
<p>[general]<br />
locale = no_NO<br />
company.name = MyCompany</p>
<p>datasource.host = localhost<br />
datasource.database = mydb<br />
datasource.username = user<br />
datasource.password = 1234</p>
<p><strong>The class for accessing the file:</strong></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
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">class</span> MyConfigClass<span style="color: #66cc66;">&#123;</span>
  protected <span style="color: #0000ff;">$config</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">config</span> = <span style="color: #000066;">parse_ini_file</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'../conf/myapp.ini'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getConfig<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$key</span> = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$key</span> !== <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">isset</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">config</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$key</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
          <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">config</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$key</span><span style="color: #66cc66;">&#93;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #66cc66;">&#123;</span>
          throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Unknown key '$key' in configuration&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
      <span style="color: #66cc66;">&#125;</span>
      <span style="color: #b1b100;">else</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">config</span>;
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setConfig<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$config</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
&nbsp;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">config</span> = <span style="color: #0000ff;">$config</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Usage:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php"><span style="color: #0000ff;">$configManager</span> = <span style="color: #000000; font-weight: bold;">new</span> MyConfigClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$value</span> = <span style="color: #0000ff;">$configManager</span>-&gt;<span style="color: #006600;">getConfig</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'datasource.host'</span><span style="color: #66cc66;">&#93;</span>;</pre></td></tr></table></div>

<p>Now, when working on larger application one usually have a application like class, and that&#8217;s a nice place to put this code. When using Prado I usually place the config code in the TApplication class.</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/05/30/simple-config-management-for-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Firefox java problem with Ubuntu 8.04 Solved!</title>
		<link>http://blog.eirikhoem.net/index.php/2008/04/30/firefox-java-problem-with-ubuntu-804-solved/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/04/30/firefox-java-problem-with-ubuntu-804-solved/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 13:18:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Firefox]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/04/30/firefox-java-problem-with-ubuntu-804-solved/</guid>
		<description><![CDATA[



I&#8217;ve been struggling with lava support for Firefox after upgrading from Ubunut 7.10 to 8.04. All I had to do was to remove the package called icedtea-gcjwebplugin. Now, I don&#8217;t know my way around lava anymore, but at least it did the trick. Worth a shot if you have problems.
Update:
John has some more information on [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-0056923567680782";
/* default */
google_ad_slot = "6546082201";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
I&#8217;ve been struggling with lava support for Firefox after upgrading from Ubunut 7.10 to 8.04. All I had to do was to <strong>remove the package called icedtea-gcjwebplugin</strong>. Now, I don&#8217;t know my way around lava anymore, but at least it did the trick. Worth a shot if you have problems.</p>
<p>Update:</p>
<p><a href="http://jwylie.blogspot.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/jwylie.blogspot.com');">John</a> has some more information on this issue if the above didnt do the trick:</p>
<p><em> I also needed to link to the new plugin….</em></p>
<p><em>cd /usr/lib/firefox-3.0/plugins$<br />
sudo ln -s /usr/lib/jvm/java-6-sun/jre/plugin/i386/ns7/libjavaplugin_oji.so</em></p>
<p>Thanks John!</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/Java" rel="tag">Java</a>, <a href="http://technorati.com/tag/Firefox" rel="tag">Firefox</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/04/30/firefox-java-problem-with-ubuntu-804-solved/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Handy online regex tool for PHP, Perl, JS and Python</title>
		<link>http://blog.eirikhoem.net/index.php/2008/04/29/handy-online-regex-tool-for-php-perl-js-and-python/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/04/29/handy-online-regex-tool-for-php-perl-js-and-python/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 10:32:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Perl]]></category>

		<category><![CDATA[Python]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/04/29/handy-online-regex-tool-for-php-perl-js-and-python/</guid>
		<description><![CDATA[



A coworker of mine has been working on a ajax enabled regex tool which lets you evaluate regex expressions in several languages (including PHP PCRE and PHP POSIX) with instant results. You can choose which functions to use, such as match, match all, replace, split etc. It also offers some basic help and hints. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-0056923567680782";
/* default */
google_ad_slot = "6546082201";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
A coworker of mine has been working on a ajax enabled regex tool which lets you evaluate regex expressions in several languages (including PHP PCRE and PHP POSIX) with instant results. You can choose which functions to use, such as match, match all, replace, split etc. It also offers some basic help and hints. It&#8217;s really handy when working on those painful expressions.</p>
<p>You can check it out at <a href="http://regex.larsolavtorvik.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/regex.larsolavtorvik.com');">http://regex.larsolavtorvik.com/</a>. Stop by <a href="http://larsolavtorvik.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/larsolavtorvik.com');">his blog</a> as well.</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/Perl" rel="tag">Perl</a>, <a href="http://technorati.com/tag/JavaScript" rel="tag">JavaScript</a>, <a href="http://technorati.com/tag/Python" rel="tag">Python</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/04/29/handy-online-regex-tool-for-php-perl-js-and-python/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Populate PDF templates with PHP / FPDF / FPDI</title>
		<link>http://blog.eirikhoem.net/index.php/2008/04/28/populate-pdf-templates-with-php-fpdf-fpdi/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/04/28/populate-pdf-templates-with-php-fpdf-fpdi/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 13:52:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Frameworks]]></category>

		<category><![CDATA[PDF]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/04/28/populate-pdf-templates-with-php-fpdf-fpdi/</guid>
		<description><![CDATA[
Ever wanted to generated PDF documents on the fly with PHP? Perhaps populate a standard contract with a customers name and address? FPDF and FPDI are two neat libraries which greatly helps when working with PDF files. FPDF is the main library for handling PDF files, while FPDI lets your import existing PDF documents into [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--><br />
Ever wanted to generated PDF documents on the fly with PHP? Perhaps populate a standard contract with a customers name and address? FPDF and FPDI are two neat libraries which greatly helps when working with PDF files. FPDF is the main library for handling PDF files, while FPDI lets your import existing PDF documents into the FPDF documents. In the code sample I&#8217;ve prepared here I&#8217;m importing a PDF template document, writing some information to the document, then sending it to the &#8220;customer&#8221;. FPDF offers several neat ways to expose the generated document, such as a stream to the browser, a string, or just storing it to file. You can download <a href="http://blog.eirikhoem.net/wp-content/uploads/2008/04/pdf_sample.zip" title="PDF Sample code">PDF Sample code</a> to test it.</p>
<p>Be sure to head on over to the <a href="http://www.fpdf.org/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.fpdf.org');">FPDF site</a> and <a href="http://www.setasign.de/products/pdf-php-solutions/fpdi/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.setasign.de');">FPDI site</a> for more information on these two libs. <a href="http://blog.eirikhoem.net/wp-content/uploads/2008/04/pdf_sample.zip" title="PDF Sample code"></a></p>
<p><strong>Related posts:</strong><br />
<a href="http://blog.eirikhoem.net/index.php/2007/06/15/generated-pdfs-over-https-with-internet-explorer/">Generated PDFs over HTTPS with Internet Explorer</a></p>
<p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/PDF" rel="tag">PDF</a>, <a href="http://technorati.com/tag/Frameworks" rel="tag">Frameworks</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/04/28/populate-pdf-templates-with-php-fpdf-fpdi/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google does a Selenium framework?</title>
		<link>http://blog.eirikhoem.net/index.php/2008/04/25/google-does-a-selenium-framework/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/04/25/google-does-a-selenium-framework/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 08:00:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[Testing]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/04/25/google-does-a-selenium-framework/</guid>
		<description><![CDATA[
I just came across this post by Mike Henke, where he writes about a presentation from the Google Automating Testing Conference. Google is working on a framework based on Selenium which they use internally. The post contains some interesting slides in addition to a presentation video.  I&#8217;ve embedded the video in this post for [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--><br />
I just came across this post by <a href="http://henke.ws/machblog/index.cfm?event=showEntry&amp;entryId=6CE7497E-19B9-BA51-EE3B15FA0CAB9A2D" onclick="javascript:pageTracker._trackPageview ('/outbound/henke.ws');">Mike Henke</a>, where he writes about a presentation from the Google Automating Testing Conference. Google is working on a framework based on Selenium which they use internally. The post contains some interesting slides in addition to a presentation video.  I&#8217;ve embedded the video in this post for your convenience, but I suggest you give Mike a visit.</p>
<p><strong>Update: Video removed, please check the links above.</strong></p>
<p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/Testing" rel="tag">Testing</a>, <a href="http://technorati.com/tag/Frameworks" rel="tag">Frameworks</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/04/25/google-does-a-selenium-framework/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Prado Framework 3.1.2 released</title>
		<link>http://blog.eirikhoem.net/index.php/2008/04/24/prado-framework-312-released/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/04/24/prado-framework-312-released/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 09:47:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Frameworks]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Prado]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/04/24/prado-framework-312-released/</guid>
		<description><![CDATA[
My favorite PHP framework just got a new release, adding several new components and fixing 30-ish bugs. The bundled JavaScript libs (Prototype / script.aculo.us) have also been upgraded, so that should help lots of people struggling with the old versions. Head on over to PradoSoft.com to download the new version. If you are new to [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--><br />
My favorite PHP framework just got a new release, adding several new components and fixing 30-ish bugs. The bundled JavaScript libs (Prototype / script.aculo.us) have also been upgraded, so that should help lots of people struggling with the old versions. Head on over to <a href="http://pradosoft.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/pradosoft.com');">PradoSoft.com</a> to download the new version. If you are new to Prado, I recommend checking out the <a href="http://pradosoft.com/demos/quickstart/" onclick="javascript:pageTracker._trackPageview ('/outbound/pradosoft.com');">Prado QuickStart tutorial</a>.</p>
<p><code><p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/Prado" rel="tag">Prado</a>, <a href="http://technorati.com/tag/Frameworks" rel="tag">Frameworks</a></p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/04/24/prado-framework-312-released/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP for science?</title>
		<link>http://blog.eirikhoem.net/index.php/2008/03/20/php-for-science/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/03/20/php-for-science/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 12:53:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/03/20/php-for-science/</guid>
		<description><![CDATA[
Jonathan Street has posted an article called Is PHP good enough for science? where he asks if anyone has experience with PHP in scientific contexts. I think PHP easily could be used to automate tasks, but I&#8217;m not aware of any toolkits or frameworks created for this purpose. Anyone seen anything like this around? If [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--></p>
<p><a href="http://torrentialwebdev.com/blog/index.php" onclick="javascript:pageTracker._trackPageview ('/outbound/torrentialwebdev.com');">Jonathan Street</a> has posted an article called <a href="http://torrentialwebdev.com/blog/archives/144-Is-PHP-good-enough-for-science.html" onclick="javascript:pageTracker._trackPageview ('/outbound/torrentialwebdev.com');">Is PHP good enough for science?</a> where he asks if anyone has experience with PHP in scientific contexts. I think PHP easily could be used to automate tasks, but I&#8217;m not aware of any toolkits or frameworks created for this purpose. Anyone seen anything like this around? If so, drop him a line.</p>
<p><code><p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a></p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/03/20/php-for-science/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New domain</title>
		<link>http://blog.eirikhoem.net/index.php/2008/03/18/new-domain/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/03/18/new-domain/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 09:13:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/03/18/new-domain/</guid>
		<description><![CDATA[Hia there. I&#8217;ve now moved my old blog to a self-hosted domain. This was mainly done to be free of the constraints that the wordpress hosting lays on you. As you might have noticed I&#8217;m experimenting with Google Adsense on various parts of the site. I&#8217;m sticking to text-only ads, and I&#8217;m trying to make [...]]]></description>
			<content:encoded><![CDATA[<p>Hia there. I&#8217;ve now moved my old blog to a self-hosted domain. This was mainly done to be free of the constraints that the wordpress hosting lays on you. As you might have noticed I&#8217;m experimenting with Google Adsense on various parts of the site. I&#8217;m sticking to text-only ads, and I&#8217;m trying to make them as non-intrusive as possible. If anyone has feedback or comments on this, I&#8217;d really like to hear from you.</p>
<p>Also, all code is now syntax highlighted <img src='http://blog.eirikhoem.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/03/18/new-domain/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setting xsi:type for objects sent over SOAP (inheritance)</title>
		<link>http://blog.eirikhoem.net/index.php/2008/03/17/setting-xsitype-for-objects-sent-over-soap-inheritance/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/03/17/setting-xsitype-for-objects-sent-over-soap-inheritance/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 14:02:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[SOAP]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[X-Fire]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/?p=28</guid>
		<description><![CDATA[
This post is pretty much a revamp of a previous post called &#8220;Working with X-Fire soap services and inheritance in PHP&#8220;. That title was a bit misleading, and not really that good when it came to providing a sample.
Let&#8217;s say we have a SOAP method called createCustomer(Customer c), and we have a base class called [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--></p>
<p>This post is pretty much a revamp of a previous post called &#8220;<a href="http://blog.eirikhoem.net/index.php/2007/05/21/working-with-x-fire-soap-services-and-inheritance-in-php/">Working with X-Fire soap services and inheritance in PHP</a>&#8220;. That title was a bit misleading, and not really that good when it came to providing a sample.</p>
<p>Let&#8217;s say we have a SOAP method called createCustomer(Customer c), and we have a base class called Customer, which has to subclasses, Person and Organization. Person has firstname, lastname, while Organization as orgname and orgid. Now, the createCustomer call accepts a object of the class Customer, and any derived classes.</p>
<p>When retrieving a Person / Organization over SOAP, PHP automatically creates instances of the correct classes, but when calling createCustomer, passing a Person / Organization it breaks. Out object is sent as a Customer, but with Person or Organization fields added. The SOAP server expects to find a xsi:type for the object we are sending to tell what kind of Customer it is. It seems like PHP does not set this itself (maybe it should?).</p>
<p>I spent quite some time looking for info on how to specify the xsi:type for the objects, and I finally came across <a href="http://no.php.net/manual/en/function.soap-soapvar-construct.php" onclick="javascript:pageTracker._trackPageview ('/outbound/no.php.net');">SoapVar</a>.</p>
<p>I created a base class which the SOAP classes extended. A method called pack is responsible for setting xsi:type.</p>
<p>(I&#8217;m very aware that my pasted code looks like a mess in this blog. I will fix that ASAP).</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
</pre></td><td class="code"><pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> BaseClass<span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #0000ff;">$namespace</span> = <span style="color: #ff0000;">&quot;http://model.api.domain.com&quot;</span>; <span style="color: #808080; font-style: italic;">// from your WSDL</span>
  protected <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #000066;">pack</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$obj</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$class_name</span> = <span style="color: #000066;">get_class</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$obj</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0000ff;">$namespace</span> = <span style="color: #ff0000;">&quot;http://model.api.domain.com&quot;</span>;
    <span style="color: #0000ff;">$pack</span> = <span style="color: #000000; font-weight: bold;">new</span> SoapVar<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$obj</span>, XSD_STRING, <span style="color: #ff0000;">&quot;$class_name&quot;</span>, <span style="color: #0000ff;">$namespace</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$pack</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> createCustomer <span style="color: #000000; font-weight: bold;">extends</span> BaseClass<span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setCustomer<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$customer</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$this</span>-&amp;gt;customer = <span style="color: #0000ff;">$this</span>-&amp;gt;pack<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$customer</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">$customer</span> = <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$customer</span>-&amp;gt;setName<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;John Doe&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$request</span> = <span style="color: #000000; font-weight: bold;">new</span> createCustomer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$request</span>-&amp;gt;setAccountID<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">123</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$request</span>-&amp;gt;setCustomer<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$customer</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$client</span>-&amp;gt;createCustomer<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$request</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>That fixed the problems for me atleast.</p>
<p><strong>PS: If your SOAP classes are prefixed you&#8217;ll need to strip the prefix in class_name when creating the SoapVar.</strong></p>
<p><strong> Related posts:</strong></p>
<ul>
<li><a href="http://blog.eirikhoem.net/index.php/2007/05/21/working-with-x-fire-soap-services-and-inheritance-in-php/">Working with X-Fire soap services and inheritance in PHP</a></li>
<li><a href="http://blog.eirikhoem.net/index.php/2008/03/13/array-problems-with-soap-and-php-updated/">Array problems with SOAP and PHP - Updated</a></li>
</ul>
<p><code><p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/SOAP" rel="tag"> SOAP</a></p>                                      </code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/03/17/setting-xsitype-for-objects-sent-over-soap-inheritance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dying with grace - PHP&#8217;s register_shutdown_function</title>
		<link>http://blog.eirikhoem.net/index.php/2008/03/15/dying-with-grace-phps-register_shutdown_function/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/03/15/dying-with-grace-phps-register_shutdown_function/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 11:08:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/?p=27</guid>
		<description><![CDATA[
Update:
I guess I didn&#8217;t make the purpose quite clear here. This method will allow you to show custom error messages when PHP hits a fatal error. The shutdown function will always run.
Scripts tend to die, and that&#8217;s not usually nice. We do not want to show the user a fatal error nor a blank page [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--></p>
<p><strong>Update:</strong></p>
<p>I guess I didn&#8217;t make the purpose quite clear here. This method will allow you to show custom error messages when PHP hits a fatal error. The shutdown function will always run.</p>
<p>Scripts tend to die, and that&#8217;s not usually nice. We do not want to show the user a fatal error nor a blank page (display errors off) . PHP has a function called <a href="http://no2.php.net/register_shutdown_function" onclick="javascript:pageTracker._trackPageview ('/outbound/no2.php.net');">register_shutdown_function</a> which lets us set up a function which is called at execution shutdown. What this means is that our function will be executed when our script is done executing / dying and PHP execution is about to shut down. By setting up a variable to false at the start of our script, and setting it to true at the very end of the script we can have our shutdown function check if the script completed successfully or not. If our variable is still false we know that we never made it to the last line of our script, hence it died somewhere. I&#8217;ve prepared a very basic sample which shows how you can give the user some proper feedback if a fatal error should arise. You&#8217;d want to turn of display of fatal errors for this to look nice.</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
</pre></td><td class="code"><pre class="php"><span style="color: #0000ff;">$clean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">function</span> shutdown_func<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #000066;">global</span> <span style="color: #0000ff;">$clean</span>;
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$clean</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066;">die</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;not a clean shutdown&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000066;">register_shutdown_function</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'shutdown_func'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$a</span> = <span style="color: #cc66cc;">1</span>;
<span style="color: #0000ff;">$a</span> = <span style="color: #000000; font-weight: bold;">new</span> FooClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// will fail with fatal</span>
&nbsp;
<span style="color: #0000ff;">$clean</span> = <span style="color: #000000; font-weight: bold;">true</span>;
?&amp;gt;</pre></td></tr></table></div>

<p>As you can see, the shutdown_func prints something if the clean variable isn&#8217;t set to true when the shutdown function runs. This should of course be wrapped in a class (and NOT use globals), and for something more usable I recommend checking <a href="http://ezcomponents.org/docs/tutorials/Execution" onclick="javascript:pageTracker._trackPageview ('/outbound/ezcomponents.org');">EZ Components way of doing this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/03/15/dying-with-grace-phps-register_shutdown_function/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
