<?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>ria-coder.com &#187; remoting</title>
	<atom:link href="http://ria-coder.com/blog/tag/remoting/feed" rel="self" type="application/rss+xml" />
	<link>http://ria-coder.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 21 Apr 2010 19:35:08 +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>Making your constructors more useful</title>
		<link>http://ria-coder.com/blog/making-your-constructors-more-useful</link>
		<comments>http://ria-coder.com/blog/making-your-constructors-more-useful#comments</comments>
		<pubDate>Mon, 30 Mar 2009 18:44:27 +0000</pubDate>
		<dc:creator>Danny Kopping</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[amfphp]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[flex remoting]]></category>
		<category><![CDATA[remoting]]></category>

		<guid isPermaLink="false">http://ria-coder.com/blog/?p=220</guid>
		<description><![CDATA[The constructor function in Object-Oriented languages is an incredibly useful mechanism to use, and we've all used them for a wide variety of solutions.]]></description>
			<content:encoded><![CDATA[<p>The constructor function in Object-Oriented languages is an incredibly useful mechanism to use, and we&#8217;ve all used them for a wide variety of solutions.</p>
<p>When i use PHP with Flex, i like taking advantage of AMFPHP&#8217;s amazingly nifty feature of being able to send whole objects as binary data to and from the server. This can be vastly useful because you could send a whole object from Flex as an ActionScript class and PHP will receive it and use it as the <em>same class</em>! Here&#8217;s a practical example:</p>
<p>You are making an application to control a university&#8217;s student details. One logical step would be to go and create a <em>Student class</em> in ActionScript 3.0:</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="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Student
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> ID<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> firstName<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> surname<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> age<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> accountPaid<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Student<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Now, if you&#8217;re using AMFPHP, it&#8217;d be a complete ball-ache to have to send the <em>Student</em> class like this (say you were inserting a student into the database):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> student<span style="color: #000066; font-weight: bold;">:</span>Student = <span style="color: #0033ff; font-weight: bold;">new</span> Student<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
student<span style="color: #000066; font-weight: bold;">.</span>firstName = <span style="color: #990000;">&quot;Jacob&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
student<span style="color: #000066; font-weight: bold;">.</span>surname = <span style="color: #990000;">&quot;Zuma&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
student<span style="color: #000066; font-weight: bold;">.</span>age = <span style="color: #000000; font-weight:bold;">67</span><span style="color: #000066; font-weight: bold;">;</span>
student<span style="color: #000066; font-weight: bold;">.</span>accountPaid = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
service<span style="color: #000066; font-weight: bold;">.</span>addStudent<span style="color: #000000;">&#40;</span>student<span style="color: #000066; font-weight: bold;">.</span>firstName<span style="color: #000066; font-weight: bold;">,</span> student<span style="color: #000066; font-weight: bold;">.</span>surname<span style="color: #000066; font-weight: bold;">,</span> student<span style="color: #000066; font-weight: bold;">.</span>age<span style="color: #000066; font-weight: bold;">,</span> student<span style="color: #000066; font-weight: bold;">.</span>accountPaid<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Wouldn&#8217;t it be so much easier to simply do this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">service<span style="color: #000066; font-weight: bold;">.</span>addStudent<span style="color: #000000;">&#40;</span>student<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>&#8230;and receive the object in PHP, and serialize it into this:</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" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000000; font-weight: bold;">class</span> Student
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$ID</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$firstName</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$surname</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$age</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$accountPaid</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</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>
&nbsp;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Well, it&#8217;s possible! I covered this is some detail in one of my <a title="Integrating Flex, AMFPHP and CodeIgniter (also including Value-Objects)" href="http://ria-coder.com/blog/integrating-flex-amfphp-and-codeigniter-with-value-objects/" target="_blank">previous tutorial</a>s, and Flex-to-PHP remoting is not in the scope of this particular post. The focus of this post, however, is to give you a couple of tips as to making your constructors more intelligent in the realm of Flex remoting. My two main areas of web development are ActionScript 3.0 and PHP5, but you can easily apply the same logic that follows to all other Object-Oriented languages.</p>
<p>Below is the improvement on my earlier <em>Student</em> class, with the more remoting-friendly constructor:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">describeType</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Student
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> ID<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> firstName<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> surname<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> age<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> accountPaid<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Student<span style="color: #000000;">&#40;</span>values<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>values<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> props<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XMLList</span> = <span style="color: #004993;">describeType</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">..</span>accessor<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> prop<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span> <span style="color: #0033ff; font-weight: bold;">in</span> props<span style="color: #000000;">&#41;</span>
					<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span>prop<span style="color: #000066; font-weight: bold;">.</span>@<span style="color: #004993;">name</span><span style="color: #000000;">&#93;</span> = values<span style="color: #000000;">&#91;</span>prop<span style="color: #000066; font-weight: bold;">.</span>@<span style="color: #004993;">name</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>* More information on the <em>describeType</em> function <a href="http://ria-coder.com/blog/acedia/">here</a>.</p>
<p>And the PHP equivalent:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000000; font-weight: bold;">class</span> Student
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$ID</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$firstName</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$surname</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$age</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$accountPaid</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$properties</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</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;">$properties</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$properties</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayObject<span style="color: #009900;">&#40;</span><span style="color: #000088;">$properties</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_object_vars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$properties</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$prop</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$prop</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now, you can easily pass an object (with no type) to either of these constructors, and they will automatically transform that object into a strongly typed, meaningful and above all else &#8211; easy to work with &#8211; variable.</p>
]]></content:encoded>
			<wfw:commentRss>http://ria-coder.com/blog/making-your-constructors-more-useful/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating CodeIgniter with AMFPHP</title>
		<link>http://ria-coder.com/blog/integrating-codeigniter-with-amfphp</link>
		<comments>http://ria-coder.com/blog/integrating-codeigniter-with-amfphp#comments</comments>
		<pubDate>Sun, 02 Nov 2008 21:09:02 +0000</pubDate>
		<dc:creator>Danny Kopping</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lessons]]></category>
		<category><![CDATA[amfphp]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[remoting]]></category>

		<guid isPermaLink="false">http://ria-coder.com/blog/?p=36</guid>
		<description><![CDATA[A while back i spent an evening hacking away at the CodeIgniter source code. I was desperate to use it as a library, as opposed to a framework. I don&#8217;t use PHP with HTML. I did for a little bit, but personally i found that HTML and CSS were the biggest load of shit languages]]></description>
			<content:encoded><![CDATA[<p>A while back i spent an evening hacking away at the CodeIgniter source code. I was desperate to use it as a library, as opposed to a framework. I don&#8217;t use PHP with HTML. I did for a little bit, but personally i found that HTML and CSS <strong>were the biggest load of shit languages ever to plague my existence! </strong>Sorry. Once i was introduced to Flash and Flex, i said <strong>&#8220;to hell with HTML and it&#8217;s ugly sister CSS! I&#8217;m becoming a banner-maker!&#8221;</strong>. Not quite&#8230; i&#8217;ve never made a banner &#8211; even though that&#8217;s like totally the whole point of Flash, dude&#8230; (insert stupid programmer comments here).</p>
<p>Ahem. Back to the point. So when i started writing Flex apps and using AMFPHP for my remoting, i desperately wanted a nice concise, easy-to-use, well documented library. Enter <a href="http://www.codeigniter.com" target="_blank">CodeIgniter</a> by Rick Ellis. Although CI is actually a MVC framework for PHP, i decided i was going to turn it into a library! (and what a ballache that was).</p>
<p>Below is the massive, complex, obfuscated script I wrote to turn it into a library. Notice how the script seems to drip with programming excellence:</p>
<pre><span>&lt;?php
    </span><span>if (!</span><span>defined</span><span>(</span><span>'BASEPATH'</span><span>)) </span><span>define </span><span>(</span><span>"BASEPATH"</span><span>, </span><span>"../CodeIgniter/system/"</span><span>);
    if (!</span><span>defined</span><span>(</span><span>'APPPATH'</span><span>)) </span><span>define </span><span>(</span><span>"APPPATH"</span><span>, </span><span>"../CodeIgniter/system/application/"</span><span>);
    if (!</span><span>defined </span><span>(</span><span>"EXT"</span><span>)) </span><span>define </span><span>(</span><span>"EXT"</span><span>, </span><span>".php"</span><span>);

    require_once (</span><span>BASEPATH</span><span>.</span><span>"codeigniter/Base5.php"</span><span>);
    require_once (</span><span>BASEPATH</span><span>.</span><span>"libraries/Controller.php"</span><span>);
    require_once (</span><span>BASEPATH</span><span>.</span><span>"codeigniter/Common.php"</span><span>);
</span><span>?&gt;</span></pre>
<p>Crazy huh? Haha. Essentially, all this script does is fuck with some of the framework architecture and allow the package to be required in PHP. See the usage below:</p>
<pre>&lt;?php
    require_once("CodeIgniter.php"); // the path to your CodeIgniter.php script as described above</pre>
<pre><span>    </span><span>class </span><span>AMFPHP_CI_Integration
    {
         function __construct() // PHP constructor
         {
                parent::Controller();  // Extend the functionality of the CI Controller class
         }
    }</span></pre>
<p><span></p>
<pre>?&gt;</pre>
<p>And that&#8217;s it! Flimsy and hackerish, i know, but hey&#8230; It works <img src='http://ria-coder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Any queries or suggestions are most welcome!</p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://ria-coder.com/blog/integrating-codeigniter-with-amfphp/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

