<?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>equivocal ramblings &#187; Coding</title>
	<atom:link href="http://www.kevinfrancis.net/journal/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kevinfrancis.net/journal</link>
	<description>the occasional journal of kevin francis</description>
	<lastBuildDate>Wed, 27 Jul 2011 08:07:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Building a SOAP Server with Zend_Soap_Server and Returning Arrays of ComplexTypes</title>
		<link>http://www.kevinfrancis.net/journal/2011/06/building-a-soap-server-with-zend_soap_server-and-returning-arrays-of-complextypes/</link>
		<comments>http://www.kevinfrancis.net/journal/2011/06/building-a-soap-server-with-zend_soap_server-and-returning-arrays-of-complextypes/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 04:23:01 +0000</pubDate>
		<dc:creator>Kevin Francis</dc:creator>
				<category><![CDATA[Brilliance]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Lazy Web]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.kevinfrancis.net/journal/?p=242</guid>
		<description><![CDATA[ZendFramework is awesome but suffers from a peculiar lack of thorough examples and documentation. To save you all some time scouring the internet fruitlessly, I will document how to use Zend_Soap_Server, and Zend_Soap_AutoDiscover in combination with Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex (try saying that &#8230; <a href="http://www.kevinfrancis.net/journal/2011/06/building-a-soap-server-with-zend_soap_server-and-returning-arrays-of-complextypes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>ZendFramework is awesome but suffers from a peculiar lack of thorough examples and documentation.</p>

<p>To save you all some time scouring the internet fruitlessly, I will document how to use <code>Zend_Soap_Server</code>, and <code>Zend_Soap_AutoDiscover</code> in combination with <code>Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex</code> (try saying that really fast a few times!).</p>

<h2>A Complete Example</h2>

<p>No one <strong>ever</strong> put together a full example in the documentation, their blog posts, the official Zend samples or anywhere else I searched yesterday. It&#8217;s always snippets here and there, and they don&#8217;t fit together well. So let me save you some trouble. I figure your reaching this page means you&#8217;ve already passed the first test which is to know the classes you need, which is why the search brought you here :)</p>

<p>I&#8217;m binding my webservice to a class, as that would be the logical choice in most cases.</p>

<pre><code>/* these are required for it all to work */
require("Zend/Soap/Server.php");
require("Zend/Soap/Wsdl.php");
require("Zend/Soap/Wsdl/Strategy/ArrayOfTypeComplex.php");
require("Zend/Soap/AutoDiscover.php");


/* my system makes use of a global prefix, feel free to do as needed */
$serviceURL = WWWPREFIX . '/webservices/myservice';


public class MyService {
     /**
     *
     * @param integer $UserID
     * @return array
     */
    function GetCoupons($UserID) {
        // do some work here
        $coupons = array(new Coupon(), new Coupon());
    }
}

// Generate WSDL relevant to code
if (isset($_GET['wsdl'])){
    $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
    $autodiscover-&gt;setClass('MyService');
    $autodiscover-&gt;handle();
} else {
    $server = new Zend_Soap_Server($serviceURL . "?wsdl");
    $server-&gt;setClass('MyService');
    $server-&gt;setObject(new MyService());
    $server-&gt;handle();
}
</code></pre>

<p>There are a few points of interest in the code block above (which is a completely functional service btw):</p>

<ul>
<li>Notice the <code>PHPDoc</code> block above the function? If you don&#8217;t get that right, it won&#8217;t work at all</li>
<li>The <em>return type of <strong><code>array</code></strong></em> because we&#8217;re returning an <em><code>array</code></em> of objects</li>
<li>The <code>Zend_Soap_AutoDiscover</code> bit at the bottom? That&#8217;ll auto-generate your <code>WSDL</code> for you</li>
</ul>

<p>There, you&#8217;re done. It should all just work, complete with WSDL auto-generation. If you&#8217;re looking to make use of an existing WSDL file, you can use the secondary method of binding to methods/functions as outlined over at the <a href="http://framework.zend.com/manual/en/zend.soap.server.html">official documentation on <code>Zend_Soap_Server</code></a>.</p>

<p>Say thank you Uncle Kevin :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinfrancis.net/journal/2011/06/building-a-soap-server-with-zend_soap_server-and-returning-arrays-of-complextypes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SVNKit + Subclipse Problems</title>
		<link>http://www.kevinfrancis.net/journal/2009/05/svnkit-subclipse-problems/</link>
		<comments>http://www.kevinfrancis.net/journal/2009/05/svnkit-subclipse-problems/#comments</comments>
		<pubDate>Thu, 21 May 2009 17:35:47 +0000</pubDate>
		<dc:creator>Kevin Francis</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Lazy Web]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://kevinfrancis.net/journal/?p=199</guid>
		<description><![CDATA[If you&#8217;re experiencing difficulty getting Subclipse working with SVNKit, install the very latest. One of the dependencies pulled in will list an SVNKit beta. Install that one and it&#8217;ll suddenly show up as a provider. This is true as of &#8230; <a href="http://www.kevinfrancis.net/journal/2009/05/svnkit-subclipse-problems/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re experiencing difficulty getting Subclipse working with SVNKit, install the very latest. One of the dependencies pulled in will list an SVNKit beta. Install <em>that</em> one and it&#8217;ll suddenly show up as a provider.</p>

<p>This is true as of Eclipse Ganymede and Subclipse 1.6.2 (installed with CollabNet Desktop). Just thought to save someone else several hours of their life :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinfrancis.net/journal/2009/05/svnkit-subclipse-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On CodeIgniter</title>
		<link>http://www.kevinfrancis.net/journal/2007/04/on-codeigniter/</link>
		<comments>http://www.kevinfrancis.net/journal/2007/04/on-codeigniter/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 13:43:40 +0000</pubDate>
		<dc:creator>Kevin Francis</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://inactiva.org/journal/2007/04/25/codeigniter-open-source-php-web-application-framework/</guid>
		<description><![CDATA[As taken from the CodeIgniter website: CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you&#8217;re a developer who lives in &#8230; <a href="http://www.kevinfrancis.net/journal/2007/04/on-codeigniter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As taken from the <a href="http://codeigniter.com/">CodeIgniter website</a>:</p>

<blockquote>
  <p>CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you&#8217;re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you&#8217;re tired of ponderously large and thoroughly undocumented frameworks</p>
</blockquote>

<p>I must say that after looking through the documentation, watching the introductory screencasts and then experimenting with it myself, it really does live up to it&#8217;s claim of real-world thoughtfulness. CodeIgniter flexible and clear when it comes to the MVC pattern, and all through the tutorials I never once felt that I didn&#8217;t quite understand what was going on. Even reading the documentation, it&#8217;s all amazingly well explained.</p>

<p>I&#8217;ve so far not felt mystified by something in the framework, and haven&#8217;t yet had to ask any questions on the forums of IRC channels &#8212; something I&#8217;ve had to do numerous times with <a href="http://cakephp.org/">CakePHP</a>, a similar open-source project. This of course isn&#8217;t to say that Cake is bad, but good documentation is king when it comes to programming.</p>

<p>Overall, the first impression you get when you run CodeIgniter is that of confidence. This is of course the benefit of having a commercial entity backing a project &#8212; little things like the documentation that typically don&#8217;t get done with a non-commercial project get taken care of.</p>

<p>Best of all? CodeIgniter comes with a <a href="http://codeigniter.com/user_guide/license.html">license</a> that qualifies as &#8216;Open Source&#8217;.</p>

<p>Lookout CakePHP, you may have the major portion of mindshare right now, but CodeIgniter is a serious contender.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinfrancis.net/journal/2007/04/on-codeigniter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FizzBuzz in PHP</title>
		<link>http://www.kevinfrancis.net/journal/2007/04/fizzbuzz-in-php/</link>
		<comments>http://www.kevinfrancis.net/journal/2007/04/fizzbuzz-in-php/#comments</comments>
		<pubDate>Thu, 12 Apr 2007 04:29:19 +0000</pubDate>
		<dc:creator>Kevin Francis</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://inactiva.org/journal/2007/04/12/fizzbuzz-in-php/</guid>
		<description><![CDATA[I was reading Why Can&#8217;t Programmers&#8230; Program today and while I find questions like these annoying at interviews because PHP isn&#8217;t really used for that sort of thing, I set myself and my colleagues the task of writing out answers. &#8230; <a href="http://www.kevinfrancis.net/journal/2007/04/fizzbuzz-in-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was reading <a href="http://www.codinghorror.com/blog/archives/000781.html">Why Can&#8217;t Programmers&#8230; Program</a> today and while I find questions like these annoying at interviews because PHP isn&#8217;t really used for that sort of thing, I set myself and my colleagues the task of writing out answers.</p>

<p>The question:</p>

<blockquote>
  <p>Print out the numbers 1 to 100. Where the number is a multiple of 3, print &#8216;Fizz&#8217;, otherwise if it is a multiple of 5 print &#8216;Buzz&#8217;. If the number is a multiple of 3 <em>and</em> 5, print &#8216;FizzBuzz&#8217;.</p>
</blockquote>

<p>Here are our answers, and mind you, they&#8217;re all in PHP.</p>

<p>Lim is our budding project coordinator turned programmer. He&#8217;s just started getting into PHP, and here&#8217;s what Lim came up with:</p>

<pre><code>for ($count=1; $count&lt;=100; $count++)
{
    if ($count%3 == 0 &amp;&amp; $count%5 ==0){
        print "FizzBuzz&lt;br /&gt;";
    }
    elseif ($count%3 == 0){
        print "Fizz&lt;br /&gt;";
    }
    elseif ($count%5 == 0){
        print "Buzz&lt;br /&gt;";
    }
    else {
        print $count."&lt;br /&gt;";
    }
}
</code></pre>

<p>An almost perfect textbook style answer.</p>

<p>Here&#8217;s what Foong came up with:</p>

<pre><code>for($i=1;$i&lt;=100;$i++)
{
    $result=$i/3;
    $result2=$i/5;

    if(!preg_match("[\.]" , $result)&amp;&amp;!preg_match("[\.]" , $result2))
    {
        echo "FizzBuzz&lt;br /&gt;";
    }
    elseif(!preg_match("[\.]" , $result))
    {
        echo "Fizz&lt;br /&gt;";
    }
    elseif(!preg_match("[\.]" , $result2))
    {
        echo "Buzz&lt;br /&gt;";
    }
    else
    {
        echo $i."&lt;br /&gt;";
    }
}
</code></pre>

<p>Certainly an example of &#8230; unique thinking. Foong&#8217;s had more than a year of experience programming in PHP, for the record.</p>

<p>Here&#8217;s what I came up with:</p>

<pre><code>foreach(range(1,100) as $i)
    echo $i % 3 == 0 ? ( $i % 5 == 0 ? "FizzBuzz\r\n" : "Fizz\r\n" ) : ( $i % 5 == 0 ? "Buzz\r\n" : $i."\r\n" );
</code></pre>

<p><strong>Update:</strong> I&#8217;ve made a change to the code, Ken Brush a.k.a. shiruken noticed I&#8217;d missed something out :(</p>

<p>I love the conditional operator @_@</p>

<p>Also, no, I would never use code like this in production, or even casual coding. I just wanted to beat my colleagues on line-count :P</p>

<p>And now, the &#8216;proper&#8217; textbook solution for all the Googlers:</p>

<pre><code>for ($i = 1; $i &lt;= 100; $i++)
{
    if($i % 3 == 0 &amp;&amp; $i % 5 ==0){
        print "FizzBuzz&lt;br /&gt;";
    }
    else if($i % 3 == 0){
        print "Fizz&lt;br /&gt;";
    }
    else if($i % 5 == 0){
        print "Buzz&lt;br /&gt;";
    }
    else {
        print $i."&lt;br /&gt;";
    }
}
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinfrancis.net/journal/2007/04/fizzbuzz-in-php/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

