<?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>CTRL-F5</title>
	<atom:link href="http://ctrl-f5.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://ctrl-f5.net</link>
	<description>Because a regular refresh is for noobs</description>
	<lastBuildDate>Wed, 08 Feb 2012 16:47:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>GoDaddy and SOPA: I&#8217;m moving [UPDATE: Done!]</title>
		<link>http://ctrl-f5.net/uncategorized/godaddy-and-sopa-im-moving/</link>
		<comments>http://ctrl-f5.net/uncategorized/godaddy-and-sopa-im-moving/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 11:32:21 +0000</pubDate>
		<dc:creator>De Maeyer Nicky</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ctrl-f5.net/?p=139</guid>
		<description><![CDATA[There has been a lot of fuzz the last weeks about GoDaddy supporting SOPA. Not only are they supporting the bill, resitricting a free and open internet, they are also releasing false statements to try and calm down customers by saying they dropped support. On the day of this writing however they have not dropped [...]]]></description>
			<content:encoded><![CDATA[<p>There has been a lot of fuzz the last weeks about GoDaddy supporting SOPA.</p>
<p>Not only are they supporting the bill, resitricting a free and open internet, they are also releasing false statements to try and calm down customers by saying they dropped support. On the day of this writing however they have not dropped their support officially.</p>
<p>No matter wether they will drop their support, i&#8217;m already looking too move my 5 domains plus hosting away from the company. If an internet company does not get how bad such a bill can, and will, be from the second they lay their eyes on it, they do not deserve any of my money.</p>
<p>I must say i have never had problems with their services or anything, but supporting SOPA is really a statement of complete idiocy, in which i will not partake. This is a completely selfish act on the behalf of GoDaddy imo, so they will loose me, among many others as a customer in the weeks to come&#8230;</p>
<p>If you too are a customer, please inform yourself about SOPA.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-f5.net/uncategorized/godaddy-and-sopa-im-moving/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Note to Self</title>
		<link>http://ctrl-f5.net/uncategorized/note-to-self/</link>
		<comments>http://ctrl-f5.net/uncategorized/note-to-self/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 23:08:09 +0000</pubDate>
		<dc:creator>De Maeyer Nicky</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ctrl-f5.net/?p=128</guid>
		<description><![CDATA[ubuntu php dev prep commands: pear prep commands: mounting shared folder in virtualbox: install sun java jdk to run PHPStorm (thx to this blog for the tip on the repo) install openVPN support in gnome]]></description>
			<content:encoded><![CDATA[<p><h6>ubuntu php dev prep commands:</h6>
<pre class="brush: bash; title: ; notranslate">
sudo apt-get install vim php5 apache2 libapache2-mod-php5 mysql-server phpmyadmin
sudo apt-get install php-pear php5-xdebug php5-sqlite php5-curl php5-svn php5-mcrypt php5-ldap phpunit
sudo a2enmod rewrite
echo 'ServerName localhost' | sudo tee /etc/apache2/httpd.conf
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
sudo service apache2 restart
sudo apt-get install subversion git git-svn
</pre>
</p>
<p><h6>pear prep commands:</h6>
<pre class="brush: bash; title: ; notranslate">
sudo pear upgrade
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear install phpunit/PHPUnit --alldeps
</pre>
</p>
<p><h6>mounting shared folder in virtualbox:</h6>
<pre class="brush: bash; title: ; notranslate">
sudo mkdir /mnt/workspace
sudo chmod 777 -R /mnt/workspace
echo '[FOLDERNAME]  /mnt/workspace  vboxsf  defaults,rw 0   0' | sudo tee /etc/fstab
sudo mount -a
</pre>
</p>
<p><h6>install sun java jdk to run PHPStorm</h6>
<pre class="brush: bash; title: ; notranslate">
sudo add-apt-repository &quot;deb http://archive.canonical.com/ maverick partner&quot;
sudo apt-get update
sudo apt-get install sun-java6-jdk
</pre>
<p><em>(thx to <a href="http://happy-coding.com/install-sun-java6-jdk-on-ubuntu-10-04-lucid/">this blog</a> for the tip on the repo)</em>
</p>
<p><h6>install openVPN support in gnome</h6>
<pre class="brush: bash; title: ; notranslate">
sudo apt-get install network-manager-openvpn-gnome
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-f5.net/uncategorized/note-to-self/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework ContextSwitch</title>
		<link>http://ctrl-f5.net/php/zend-framework-contextswitch/</link>
		<comments>http://ctrl-f5.net/php/zend-framework-contextswitch/#comments</comments>
		<pubDate>Thu, 11 Aug 2011 10:33:43 +0000</pubDate>
		<dc:creator>De Maeyer Nicky</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[contextswitch]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://ctrl-f5.net/?p=123</guid>
		<description><![CDATA[Today was the day I got tired of constantly disabling the layout and viewRenderer when making ajax calls in the ZF project I&#8217;m currently working on. Today is the day I went and visited my old friend, the Zend Framework ContextSwitch Action Helper. I have used the contextSwitch before, but it was some time ago, [...]]]></description>
			<content:encoded><![CDATA[<p>Today was the day I got tired of constantly disabling the layout and viewRenderer when making ajax calls in the ZF project I&#8217;m currently working on.<br />
Today is the day I went and visited my old friend, the Zend Framework ContextSwitch Action Helper.<span id="more-123"></span></p>
<p>I have used the contextSwitch before, but it was some time ago, and once setup you don&#8217;t have to look at it that much anymore, so I guess that&#8217;s why I forgot how it worked&#8230;<br />
A quick reminder is to follow, including some caveats I encountered while doing the setup.</p>
<p>First things first, initialising the contextSwitch, which I did in a base controller:</p>
<pre class="brush: php; title: ; notranslate">
abstract class BaseController extends \Zend_Controller_Action
{
    /**
     * Helper to get better code completion
     *
     * @var $conSwitch \Zend_Controller_Action_Helper_ContextSwitch
     */
    protected $contextSwitch = null;

    public function init()
    {
        parent::init();

        $this-&gt;contextSwitch = $this-&gt;_helper-&gt;contextSwitch();
        $this-&gt;contextSwitch
                -&gt;setContext('html', array(
                    'suffix' =&gt; ''
                ))
                -&gt;setAutoDisableLayout(true)
                -&gt;setAutoJsonSerialization(true)
                -&gt;setDefaultContext('html')
                -&gt;initContext();
    }
}
</pre>
<p>Fairly easy, or so it seems. There are some oddities in the contextSwitch I was struggling with&#8230;</p>
<h3>HTML context</h3>
<p>For starters, there is no default html context available. This is very odd, since the framework is build to generate HTML pages&#8230;<br />
This was easily overcome by just adding it. Note the use of setContext() rather than addContext(), this ensures the context is overwritten when it should exist in the future (after ZF update or someone adds it in a superclass).<br />
I&#8217;m also setting an empty suffix, so the default .phtml files will be rendered when using the html context, if I were to set this to &#8216;html&#8217;, the viewRenderer would look for &#8216;my-action.html.phtml&#8217;</p>
<h3>setDefaultContext()</h3>
<p>Now this one is weird, I actually do not know if this one does anything at all&#8230; When in a sub-classed controller action method, which was requested without a &#8216;format&#8217; get parameter, and I execute the following command:</p>
<pre class="brush: php; title: ; notranslate">
$this-&gt;contextSwitch-&gt;getCurrentContext();
</pre>
<p>It just returns NULL&#8230;</p>
<h3>Adding action contexts</h3>
<p>When I put the above code to use, it was not working. Well, when performing an ajax request to an action, even with the &#8216;format&#8217; GET parameter set to &#8216;html&#8217;, the contextSwitch did not disable the layout for instance.<br />
To resolve this I added a context for the action I was testing, explicitly:</p>
<pre class="brush: php; title: ; notranslate">
//in the correct controller
public function init()
{
    parent::init();

    $this-&gt;contextSwitch
            -&gt;addActionContext('index', array('html'));
}
</pre>
<p>Good to go , right? hmm, wrong&#8230; Still did not do what I expected it to do, so alt-tabbed and ctrl-T to Google. The solution?</p>
<pre class="brush: php; title: ; notranslate">
//in the correct controller
public function init()
{
    parent::init();

    $this-&gt;contextSwitch
            -&gt;addActionContext('index', array('html'))
            -&gt;initContext(); //init again!!!
}
</pre>
<p><strong>init again!!!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-f5.net/php/zend-framework-contextswitch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building PHP with bundeled GD on Ubuntu</title>
		<link>http://ctrl-f5.net/php/building-php-with-bundeled-gd-on-ubuntu/</link>
		<comments>http://ctrl-f5.net/php/building-php-with-bundeled-gd-on-ubuntu/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 12:29:00 +0000</pubDate>
		<dc:creator>De Maeyer Nicky</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://ctrl-f5.net/?p=117</guid>
		<description><![CDATA[I was having trouble with some GD library functions not working in my PHP5.3 install on Ubuntu. Apparently Debian distributions do not compile PHP with the bundeled GD library, since it is a branch of the original GD, they consider it insecure. To fix this problem I downloaded the sources and compiled PHP with the [...]]]></description>
			<content:encoded><![CDATA[<p>I was having trouble with some GD library functions not working in my PHP5.3 install on Ubuntu. Apparently Debian distributions do not compile PHP with the bundeled GD library, since it is a branch of the original GD, they consider it insecure.<br />
To fix this problem I downloaded the sources and compiled PHP with the correct GD library.</p>
<p><span id="more-117"></span></p>
<p>Most of the stuff I&#8217;m about to do is from the <a href="http://cumu.li/2008/5/13/recompiling-php5-with-bundled-support-for-gd-on-ubuntu" target="_blank">a blog post by Ant on CuMu.li</a>, so kudos there. It got me well on my way, but I still had a few issues. The first steps worked perfect:</p>
<pre class="brush: bash; title: ; notranslate">
$ cd /usr/src
$ sudo apt-get source php5
$ sudo apt-get install build-essential debhelper fakeroot
$ sudo apt-get build-dep php5
$ cd php5-5.x.x
$ sudo vim debian/rules
</pre>
<p>In this file search for &#8220;&#8211;with-gd=shared,/usr &#8211;enable-gd-native-ttf&#8221; and change it to &#8220;&#8211;with-gd=shared &#8211;enable-gd-native-ttf&#8221;.<br />
So far so good, but running the &#8220;dpkg-buildpackage -rfakeroot&#8221; command failed on my machine, with the following error:</p>
<pre class="brush: bash; title: ; notranslate">
# start our own mysql server for the tests
/bin/sh debian/setup-mysql.sh 1025 /usr/src/php5-x.x.x/mysql_db
Timed out waiting for mysql server to be available
kill: 65: No such process

kill: 65: No such process

make: *** [test-results.txt] Error 1
dpkg-buildpackage: error: debian/rules build gave error exit status 2
</pre>
<p>This is caused because the mysql server refuses to run under root, but I had to be root to be able to build the package. After googling for a while I found the solution:</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo vim debian/setup-mysql.sh
</pre>
<p>In this file comment the line starting the server, and copy the command, adding the &#8220;&#8211;user=root&#8221; parameter:</p>
<pre class="brush: bash; title: ; notranslate">
# Start the daemon
#$mysqld &gt; $datadir/run.log 2&gt;&amp;1 &amp;
#add root user
$mysqld --user=root &gt; $datadir/run.log 2&gt;&amp;1 &amp;
</pre>
<p>Now the built succeeded, and after install GD worked correctly.</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo dpkg-buildpackage -rfakeroot
$ dpkg -i php5-gd_5.3.5-1ubuntu7.2_amd64.deb
</pre>
<p>This should normally restart apache2, but if it does not you can do this with the services utility:</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo service apache2 restart
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-f5.net/php/building-php-with-bundeled-gd-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Closures in PHP5.4 alpha</title>
		<link>http://ctrl-f5.net/php/closures-in-php5-4-alpha/</link>
		<comments>http://ctrl-f5.net/php/closures-in-php5-4-alpha/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 15:35:57 +0000</pubDate>
		<dc:creator>De Maeyer Nicky</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5.4]]></category>

		<guid isPermaLink="false">http://ctrl-f5.net/?p=99</guid>
		<description><![CDATA[The PHP community has been on a roll lately, after the great new release of PHP5.3 last year, a shiny new alpha is seeing light aka PHP5.4. The featurelist is not as big as the one of the previous release. But that&#8217;s because the previous one was huge&#8230; sporting stuff like namespaces, anonymous functions and [...]]]></description>
			<content:encoded><![CDATA[<p>The PHP community has been on a roll lately, after the great new release of PHP5.3 last year, a shiny new alpha is seeing light aka PHP5.4. The featurelist is not as big as the one of the previous release. But that&#8217;s because the previous one was huge&#8230; sporting stuff like namespaces, anonymous functions and late static binding.<br />
PHP5.4 is mostly aimed at improving the previous release, but also gives us devs some nice features to enhance our codebase.<span id="more-99"></span> most notable are:</p>
<ul>
<li>addition of Traits</li>
<li>array dereferencing support</li>
<li>$this support in closures</li>
<li>indirect method call through an array</li>
</ul>
<p>All of these might one day get an article, if I manage to do some testing, but for now I&#8217;ve only tested the closure enhancements. And with some unexpected results.</p>
<p>If one would create a closure inside a class, PHP5.4 will put that closure inside the same scope as a regular class method. This does not only make $this available inside the closure, but you can also access protected and private methods of said class.<br />
I&#8217;ve put a little script together to test this:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
class Test {
    public function testAccess()
    {
        echo PHP_EOL.'-- testing access from within class function '.PHP_EOL;
        $this-&gt;testPublic();
        $this-&gt;testProtected();
        $this-&gt;testPrivate();
        echo PHP_EOL;
    }

    public function getClos() {
        return function ($val) {
            echo PHP_EOL.'== Test from within closure'.PHP_EOL;
            echo $val.PHP_EOL;
            var_dump($this);
            $this-&gt;testPublic();
            $this-&gt;testProtected();
            $this-&gt;testPrivate();
            echo PHP_EOL;
        };
    }

    public function testPublic()
    {
        echo 'can access Public!'.PHP_EOL;
    }

    protected function testProtected()
    {
        echo 'can access Protected!'.PHP_EOL;
    }

    private function testPrivate()
    {
        echo 'can access private!'.PHP_EOL;
    }
}

class TestInher extends Test {
    public function testAccess()
    {
        echo PHP_EOL.'-- testing access from within class function '.PHP_EOL;
        $this-&gt;testPublic();
        $this-&gt;testProtected();
        $this-&gt;testPrivate();
        echo PHP_EOL;
    }

    public function testPublic()
    {
        echo 'accessing the overridden public function'.PHP_EOL;
    }
}

$test = new Test;
$test-&gt;testAccess();
$clos = $test-&gt;getClos();
$clos('testing closure');

$testInher = new TestInher;
$testInher-&gt;testAccess();
$clos = $testInher-&gt;getClos();
$clos('testing closure from inherited class');
</pre>
<p>Now as you would expect, line 46 will fail, because an inherited class can not access a private method of a parent. This is the output of the script with line 46 commented out:</p>
<pre class="brush: bash; title: ; notranslate">
-- testing access from within class function
can access Public!
can access Protected!
can access private!

== Test from within closure
testing closure
object(Test)#1 (0) {
}
can access Public!
can access Protected!
can access private!

-- testing access from within class function
accessing the overridden public function
can access Protected!

== Test from within closure
testing closure from inherited class
object(TestInher)#3 (0) {
}
accessing the overridden public function
can access Protected!
can access private!
</pre>
<p>The most notable lines here are 20 and 24. The former stating that $this is an object of type &#8216;TestInher&#8217;, but the latter $this-&gt;testPrivate() does not result in an error!<br />
I do not know if this was intended behaviour, but will check this through the appropriate channels, an update will follow.</p>
<p>All in all this is a very neat improvement, that I am sure will please lots of devs, me included.</p>
<p><b>[UPDATE]</b></p>
<p>After looking at the code again I realised it&#8217;s just intended behavior, as it would be exactly the same thing as adding this method to class Test:</p>
<pre class="brush: php; title: ; notranslate">
    public function sameAsClosure()
    {
        echo PHP_EOL.'== Test from within sameAsClosureFunction'.PHP_EOL;
        echo $val.PHP_EOL;
        var_dump($this);
        $this-&gt;testPublic();
        $this-&gt;testProtected();
        $this-&gt;testPrivate();
        echo PHP_EOL;
    }
</pre>
<p>From inside the scope of the parent class we can access its private methods, and if we were to extends it, we can also call the public sameAsClosure() method from any scope.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-f5.net/php/closures-in-php5-4-alpha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debian based Linux flash plugin</title>
		<link>http://ctrl-f5.net/uncategorized/debian-based-linux-flash-plugin/</link>
		<comments>http://ctrl-f5.net/uncategorized/debian-based-linux-flash-plugin/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 12:26:58 +0000</pubDate>
		<dc:creator>De Maeyer Nicky</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ctrl-f5.net/?p=95</guid>
		<description><![CDATA[Lot&#8217;s of websites are still using Flash to play movies. I personally think this is counter productive because of it&#8217;s pour compatibility, and support not beeing native. It&#8217;s biggest competitor at the moment is HTML5. It can do video playback natively in the browser, with hardware acceleration and better power management. HTML5 also does not [...]]]></description>
			<content:encoded><![CDATA[<p>Lot&#8217;s of websites are still using Flash to play movies. I personally think this is counter productive because of it&#8217;s pour compatibility, and support not beeing native. It&#8217;s biggest competitor at the moment is HTML5. It can do video playback natively in the browser, with hardware acceleration and better power management. HTML5 also does not exclude a large userbase of iOS internetters.<span id="more-95"></span></p>
<p>If you are running Ubuntu or any other Debian based Linux chances are that you&#8217;re having trouble playing flash in your browser. The install is just unwieldy, because adobe does not have very good linux support and all&#8230; The regular version I installed from Adobe Labs gave white squares over the video where stuff was moving a lot, or where buttons are present. Today I stumbled upon the solution for my troubles. It comes in the form of an easy FireFox extension that deletes the Flash plugins you have installed wrongly, and downloads+installs the correct one, in addition some configs are mended so everything runs perfectly.</p>
<p>Link to the extension: <a href="https://addons.mozilla.org/en-US/firefox/addon/flash-aid/">https://addons.mozilla.org/en-US/firefox/addon/flash-aid/</a><br />
Does exactly what it says on the box! Flash videos are going quite nice now on my Ubuntu 10.04</p>
<p>PS: I have tried this with FF4 without any problems, even though the page does only say 3.5 atm.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-f5.net/uncategorized/debian-based-linux-flash-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading GoDaddy to 4th Generation Hosting (4GH)</title>
		<link>http://ctrl-f5.net/uncategorized/upgrading-godaddy-to-4th-generation-hosting-4gh/</link>
		<comments>http://ctrl-f5.net/uncategorized/upgrading-godaddy-to-4th-generation-hosting-4gh/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 09:10:03 +0000</pubDate>
		<dc:creator>De Maeyer Nicky</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[4GH]]></category>
		<category><![CDATA[GoDaddy]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://ctrl-f5.net/?p=93</guid>
		<description><![CDATA[Godaddy recently &#8220;upgraded&#8221; their hosting capabilities. As they call it: 4GH. Now this is probably all just marketing tricks, especially because they still do not support PHP5.3 officially on shared hosting&#8230; (workaround here (not tested yet)) They also publicise the fact that there are EU servers now, but I&#8217;m not sure if that&#8217;s actually a [...]]]></description>
			<content:encoded><![CDATA[<p>Godaddy recently &#8220;upgraded&#8221; their hosting capabilities. As they call it: 4GH. Now this is probably all just marketing tricks, especially because they still do not support PHP5.3 officially on shared hosting&#8230; (workaround <a href="http://www.1point21.org/web-development/godaddy-linux-shared-hosting-php-53">here</a> (not tested yet))</p>
<p>They also publicise the fact that there are EU servers now, but I&#8217;m not sure if that&#8217;s actually a new thing&#8230; anyway, I wanted to make sure I was in on the goodness.<br />
A one sentence google got me there right away, the server is upgrading for free as I&#8217;m typing.<br />
go get yours <a href="http://help.godaddy.com/article/6190">here</a>, your hosting will be upgraded within the 72 hours.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-f5.net/uncategorized/upgrading-godaddy-to-4th-generation-hosting-4gh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Service Layer and Zend Framework part2</title>
		<link>http://ctrl-f5.net/php/service-layer-and-zend-framework-part2/</link>
		<comments>http://ctrl-f5.net/php/service-layer-and-zend-framework-part2/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 23:11:13 +0000</pubDate>
		<dc:creator>De Maeyer Nicky</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Service Layer]]></category>

		<guid isPermaLink="false">http://ctrl-f5.net/?p=70</guid>
		<description><![CDATA[Since my <a href="http://ctrl-f5.net/php/service-layer-in-php/">last post</a>, I've had some time to reflect on my take on a ServiceLayer and do a little experimentation. This time it around it won't be all talk and no action though, time to get your code-writing-mittens on. For the purpose of this post I have created a <a href="https://github.com/ctrl-f5/Zend-Framework-ServiceLayer">GitHub repository</a>, as the series will progress (if it ever will of course) I should end up with a descent, flexible, robust implementation.
A few points are to be made clear before we get our hands dirty. I will only be using stable libraries, so no ZF2 for now, I'll be sticking to ZF1.11. (Although Matthew Weier O'Phinney <a href="http://weierophinney.net/matthew/archives/248-Introducing-the-ZF2-Plugin-Broker.html">wrote a nice introduction about the new plugin broker architecture in ZF2</a> which will come in handy in situations like this...). Luckily the autoloader rewrite in ZF 1.10 will allow us to use PHP 5.3 namespaces in our library classes. Another new PHP feature that will come in handy will be <a href="http://php.net/manual/en/language.oop5.late-static-bindings.php">Late Static Binding</a>.]]></description>
			<content:encoded><![CDATA[<p>Since my <a href="http://ctrl-f5.net/php/service-layer-in-php/">last post</a>, I&#8217;ve had some time to reflect on my take on a ServiceLayer and do a little experimentation. This time it around it won&#8217;t be all talk and no action though, time to get your code-writing-mittens on. For the purpose of this post I have created a <a href="https://github.com/ctrl-f5/Zend-Framework-ServiceLayer">GitHub repository</a>, as the series will progress (if it ever will of course) I should end up with a descent, flexible, robust implementation.<br />
A few points are to be made clear before we get our hands dirty. I will only be using stable libraries, so no ZF2 for now, I&#8217;ll be sticking to ZF1.11. (Although Matthew Weier O&#8217;Phinney <a href="http://weierophinney.net/matthew/archives/248-Introducing-the-ZF2-Plugin-Broker.html">wrote a nice introduction about the new plugin broker architecture in ZF2</a> which will come in handy in situations like this&#8230;). Luckily the autoloader rewrite in ZF 1.10 will allow us to use PHP 5.3 namespaces in our library classes. Another new PHP feature that will come in handy will be <a href="http://php.net/manual/en/language.oop5.late-static-bindings.php">Late Static Binding</a>.<span id="more-70"></span></p>
<p>As you can see in the github repo, there&#8217;s a library folder Ctrl, which will contain only namespaced classes. ZF can load these automatically through the following line in the app.ini file:</p>
<pre class="brush: bash; title: ; notranslate">
autoloadernamespaces[] = &quot;Ctrl&quot;
</pre>
<p>The first file we&#8217;ll look at is the interface for a service: lib/Ctrl/Service/IService.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace Ctrl\Service;

interface IService
{
    static function getType();
    static function factory(array $options = array());
    function getOptions();
}
</pre>
<p>For creating services it they will implement a factory method, which accepts an array of options. These options can later only be retrieved.<br />
The getType() function will allow us to retrieve the fully qualified class name without having to work with string, which will make the code more maintainable.</p>
<p>On this interface the abstract service class is built: lib/Ctrl/Service/Service.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace Ctrl\Service;

abstract class Service implements IService
{
    protected $_options = array();

    public function __construct(array $options = array())
    {
        $this-&gt;_setOptions($options);
        $this-&gt;init();
    }

    /**
     * Constructs a Service instance
     *
     * @param array $options
     * @return Ctrl\Service\Service
     */
    public static function factory(array $options = array())
    {
        $class = self::getType();
        return new $class($options);
    }

    protected function _setOptions(array $options)
    {
        $this-&gt;_options = $options;
    }

    public function getOptions()
    {
        return $this-&gt;_options;
    }

    public static function getType()
    {
        return get_called_class();
    }

    protected function init() {}
}
</pre>
<p>This is a pretty simple implementation but it will do for now. What this allows us to do is call the service from anywhere using the factory method:</p>
<pre class="brush: php; title: ; notranslate">
$logService = Log_Service_Test::factory(array('logDir' =&gt; '/var/log'));
$logService-&gt;archiveLogbook(array('file' =&gt; 'errors.log'));
</pre>
<p>In the github repo, you can also find an action controller extension which adds a servicebroker to controllers. The service broker will allow to configure a service and retrieve stored services easily, while at the same time provide functionality to create custom services. That component is still somewhat of a work in progress, so maybe there will be an post about it later on&#8230; I&#8217;ll give you a little taste of what is going around at the moment of writing:</p>
<pre class="brush: php; title: ; notranslate">
public function testServicesAction()
{
    //old way, stil lpossible of cource
    $service1 = Log_Service_Test::factory(array('test' =&gt; 'my first service'));

    //calling service for the first time will set the options
    $service2 = $this-&gt;_services-&gt;getService(Log_Service_Test::getType(), array('optionsTest' =&gt; 'viaBroker! &gt; these options will be set'));

    //calling second time will return the previous instance
    $service3 = $this-&gt;_services-&gt;getService(Log_Service_Test::getType(), array('second' =&gt; 'viaBroker! &gt; these options will be ignored'));

    //so $service2 === $service3 and has the options as defined in the call to create $service2

    //requesting a service through the getLocalService method will skip the internal register and will always create
    //the service with the options passed, this instance will not be saved by the broker
    $service4 = $this-&gt;_services-&gt;getLocalService(Log_Service_Test::getType(), array('third' =&gt; 'viaBroker! --local'));
}
</pre>
<p>So it&#8217;s a start, but not sure if this is a good way of doing it&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-f5.net/php/service-layer-and-zend-framework-part2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHPUnit and floating point precision</title>
		<link>http://ctrl-f5.net/php/phpunit-and-floating-point-precicion/</link>
		<comments>http://ctrl-f5.net/php/phpunit-and-floating-point-precicion/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 12:48:26 +0000</pubDate>
		<dc:creator>De Maeyer Nicky</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[floating-point-precicion]]></category>
		<category><![CDATA[language-features]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[PHPUnit]]></category>

		<guid isPermaLink="false">http://ctrl-f5.net/?p=56</guid>
		<description><![CDATA[Last week I&#8217;ve had some trouble unit testing a function that converted a point on a map given in degrees, minutes and seconds, to a longitude and a latitude. I did not write the function myself, but was only unit testing it. PHPUnit gave me some weird output, from which I could not extract a [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I&#8217;ve had some trouble unit testing a function that converted a point on a map given in degrees, minutes and seconds, to a longitude and a latitude. I did not write the function myself, but was only unit testing it. PHPUnit gave me some weird output, from which I could not extract a cause. Some mighty debugging got me to the bottom of it.<span id="more-56"></span></p>
<p>Consider the following class:</p>
<pre class="brush: php; title: ; notranslate">
class MyClass
{
    public function getData()
    {
        $degrees = '10';
        $minutes = '45';
        $seconds = '16';
        return array(
            'int' =&gt; 1,
            'float' =&gt; $degrees + ($minutes/60 ) + ($seconds/3600 ),
            'string' =&gt; 'myString'
        );
    }
}
</pre>
<p>Notice the hard-coded values as strings, as if they are coming straight out of a file or database. Not that it makes any difference for this example.<br />
If we now know the solution to the calculation beeing made, we can write a unit test. We can do this because our test environment is fully controlled per test, so we know exactly what values are sent to the class. (Allthough they are just hardcoded here for simplicity):</p>
<pre class="brush: php; title: ; notranslate">
class MyClassTest extends PHPUnit_Framework_TestCase
{
    public function testGetData()
    {
        require_once 'MyClass.php';
        $subject = new MyClass();

        $expected = array(
            'int' =&gt; 1,
            'float' =&gt; 10.754444444444,
            'string' =&gt; 'myString'
        );
        $actual = $subject-&gt;getData();

        $this-&gt;assertEquals($expected, $actual);
    }
}
</pre>
<p>Running the unit test will result in the following:</p>
<pre class="brush: bash; title: ; notranslate">
There was 1 failure:

1) MyClassTest::testGetData
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array
 (
     [float] =&gt; 10.754444444444
     [int] =&gt; 1
     [string] =&gt; myString
 )

/test/TestClass.php:20
</pre>
<p>So PHPUnit tells us the 2 arrays are not equal, but it can not tell us what is wrong with it&#8230; This isÂ of courseÂ a strange quirk brought to you by the marry world of floating point precicion. The <a href="http://php.net/float" target="_blank">PHP Manual</a> also makes this clear by stating: &#8220;So never trust floating number results to the last digit, and never compare floating point numbers for equality.&#8221;<br />
This problem can be fixed in several ways, these 2 will both result in a valid Unit Test:</p>
<p>1: change the line where the number is hard-coded to the equal calculation used in the class:</p>
<pre class="brush: php; title: ; notranslate">
        //change this
        $expected = array(
            'int' =&gt; 1,
            'float' =&gt; 10.754444444444,
            'string' =&gt; 'myString'
        );
        //to this
        $expected = array(
            'int' =&gt; 1,
            'float' =&gt; 10 + (45/60) + (16/3600),
            'string' =&gt; 'myString'
        );
</pre>
<p>2: alter the result by rounding it</p>
<pre class="brush: php; title: ; notranslate">
        $actual = $subject-&gt;getData();
        //add this line
        if (array_key_exists('float', $actual)) $actual['float'] = round($actual['float'], 12);
</pre>
<p>There are a couple of other options to get this test working like extending PHPUnit to check value types and acting accordingly. Best way is to put this in a custom assert method which you can use when you know there can be floating point troubles.<br />
Another solution might come from using the <a href="http://www.php.net/manual/en/ref.bc.php" target="_blank">BC Math Functions</a>, allthough I&#8217;m not sure about this one&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-f5.net/php/phpunit-and-floating-point-precicion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Service Layer in PHP</title>
		<link>http://ctrl-f5.net/php/service-layer-in-php/</link>
		<comments>http://ctrl-f5.net/php/service-layer-in-php/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 17:11:02 +0000</pubDate>
		<dc:creator>De Maeyer Nicky</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Service Layer]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://ctrl-f5.net/?p=36</guid>
		<description><![CDATA[I've been thinking about robust, extensible, and easy patterns or strategies for setting up an application. Starting from an MVC viewpoint, I feel there's a need for an extra layer, a service layer.
The service layer can handle workflow that only represents business logic. This meas the Controllers and Models can focus on their own tasks, being handling request logic and persistence logic respectively.
Service layer is a broad concept, and there are many ideas and examples available, for different languages and frameworks. My goal is to try and sculpt it in such a way that it fits in with PHP and Zend Framework.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking about robust, extensible, and easy patterns or strategies for setting up an application. Starting from an MVC viewpoint, I feel there&#8217;s a need for an extra layer, a service layer.<br />
The service layer can handle workflow that only represents business logic. This meas the Controllers and Models can focus on their own tasks, being handling request logic and persistence logic respectively.<br />
Service layer is a broad concept, and there are many ideas and examples available, for different languages and frameworks. My goal is to try and sculpt it in such a way that it fits in with PHP and Zend Framework.<span id="more-36"></span></p>
<p>There are a couple of basic programming rules or guidelines you can to follow to make your system works, following them will make your system better in multipleÂ disciplines:</p>
<ul>
<li>easy to extend or add features</li>
<li>consistentÂ API, easy to understand for new developers</li>
<li>highly testable, and thus robust</li>
<li>â€¦</li>
</ul>
<p>The basic points on the agenda to accomplish such a system are:</p>
<ul>
<li>keep logic separated, in this case: request, business and persistence logic</li>
<li>keep functional logic separated from object creation logic</li>
<li>work with interfaces where possible</li>
</ul>
<p>Now this is all quite high level, just to give a quick overview. Next up is a more in depth look at how this will translate to the structure of the application.</p>
<h3>To keep the logic separated</h3>
<p>Specific logic will be assigned to an appropriate place where they can do there thing. Sounds easy enough.<br />
<strong><br />
</strong><strong> The request logic</strong> will be handled by the Controllers:<br />
Controllers take in request data and validate it, and determine whether to redirect or display output, and in the latter case, the format of the output. If a controller wants to perform any action related to business or persistence logic it consults the service layer.<br />
<strong><br />
The business logic</strong> will be handled completely by the service layer:<br />
Most MVC frameworks in the PHP landscape use fat models, who combine persistence logic with business logic. Although the persistence logic is delegated to a database abstraction layer beneath the models in most implementations, this approach still creates a high coupling between business and persistence logic. <em>(P.S.: And if the model&#8217;s aren&#8217;t stuffed with both business and persistence logic, your controllers are probably bloated with request and business logic)</em><br />
The business logic will be extracted into a service layer, which leaves the model with only getters and setters, and some persistence logic which it further delegates.<br />
<strong><br />
The persistence logic</strong> will be delegated to a database abstraction layer, there are plenty around, the goal is to be able to use any with the service layer, but there will be a specific focus on Zend_Db_Table and Doctrine ORM.</p>
<h3>Extract object creation logic</h3>
<p>This is a widely practiced art, the factory method, abstract factory pattern and registry pattern are found all over Zend Framework. It makes for easy configuration and dependency injection. In creating factories and registries, the ZF naming will be used, e.g.: <code>Service::factory()</code> or <code>$this-&gt;_serviceBroker</code>.<br />
This will benefit the code in both usability, consistency, and testability. It creates a consistent API for the developers, and makes dependency injection easy when writing unit tests. Working with interfaces and abstract classes will help a lot in this area.<br />
Abstracted object creation also means high configurability, the factories creating the objects, can access the configuration and can perform actions on objects before they are released to be used. For instance if you ask a factory to create a UserService, you can configure the factory to subscribe a logger that reacts to certain events the UserService raises.</p>
<h4>Side note</h4>
<p>PHP 5.3 brings some nice new features to the party like late static binding which is really a godsend for creating abstract factories or implementing factory methods. If you&#8217;ve have it available, and are working with any factory patterns, be sure to check it out.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-f5.net/php/service-layer-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

