<?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>amptools &#187; midori-php</title>
	<atom:link href="http://www.amptools.net/tag/midori-php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.amptools.net</link>
	<description>Simplify your life.</description>
	<lastBuildDate>Sat, 08 May 2010 07:40:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Boxing and Unboxing in PHP</title>
		<link>http://www.amptools.net/blog/boxing-and-unboxing-in-php</link>
		<comments>http://www.amptools.net/blog/boxing-and-unboxing-in-php#comments</comments>
		<pubDate>Tue, 16 Jun 2009 18:06:48 +0000</pubDate>
		<dc:creator>Michael Herndon</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Boxing]]></category>
		<category><![CDATA[Chaining]]></category>
		<category><![CDATA[midori-php]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[type boxing]]></category>
		<category><![CDATA[unboxing]]></category>

		<guid isPermaLink="false">http://www.amptools.net/?p=102</guid>
		<description><![CDATA[If you are not familiar with type/value boxing using objects, head over to wikipedia&#8217;s object_type article to grasp the concept. While languages such as Java and C# support this natively, PHP does not. However it can be accomplished, to some degree in PHP, just not eloquently as the language itself does not have constructs to [...]]]></description>
			<content:encoded><![CDATA[<img class='gravatar' style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=899a978b0f02774a965aec11eeb0b8f4&amp;default=http://amppotls.net' alt='No Gravatar' width=48 height=48/><p>If you are not familiar with type/value boxing using objects, head over to <a href="http://en.wikipedia.org/wiki/Object_type" rel="tag">wikipedia&#8217;s object_type article</a> to grasp the concept. While languages such as Java and C# support this natively, PHP does not. However it can be accomplished, to some degree in PHP, just not eloquently as the language itself does not have constructs to support it.&#160; Having box types in PHP could help with chaining, keeping everything object oriented and allows for type hinting in method signatures.&#160; The downside is overhead and the fact that you now have extra checking to do using the â€œinstanceofâ€ construct.&#160; Having a type system is also a plus when using development tools that have intellisense or code assist like PDT. Rather than having to google/bing/yahoo for the method, it exists on the object, and you can use the tool to provide a drop down.</p>
<h3> Boxing and Unboxing with Midori PHP </h3>
<p>In <a href="/projects/midori-php/" rel="tag">Midori PHP</a> Iâ€™ve add box types for native values in PHP. Granted not all the types are there yet, as iâ€™m slowly porting them in, writing documentation, writing tests, and refactoring what currently exists from the prototype.&#160; The key classes to look at would be the <a href="http://github.com/michaelherndon/midori-php/blob/9e83502e28cbc278ec6bb4a293331dce9fa9dc7f/src/Midori/Object.php" rel="tag">Midori_Object</a>, <a href="http://github.com/michaelherndon/midori-php/blob/9e83502e28cbc278ec6bb4a293331dce9fa9dc7f/src/Midori/Nullable.php" rel="tag">Midori_Nullable</a>, and <a href="http://github.com/michaelherndon/midori-php/blob/9e83502e28cbc278ec6bb4a293331dce9fa9dc7f/src/Midori/String.php" rel="tag">Midori_String</a>.&#160; The Midori_Nullable class currently abstracts a nullable value into a class which is built on the Midori_Object and is the parent of Midori_String.&#160; So using these box classes might look like the follow:&#160; </p>
<h4>PHP</h4>
<pre class="brush: php;">

	// boxing example
	$str = new Midori_String(&quot;my cool new value&quot;); // value is now boxed
	$str2 = $str-&gt;replace(&quot;value&quot;, &quot;test&quot;);

	// unboxing
	$unboxedStr = $str2-&gt;value; // unboxed value

	echo $unboxedStr; // my cool new test
	echo $str // my cool new value
	echo $str2 // my cool new test
</pre>
<p>
Midori_String uses the magic method __toString to allow echo to called on the object and the Midori_String will even allow for dot concatination since it has __toString.&#160;  The &#8220;value&#8221; property is the actual value inside of the Midori_String box object to which it wraps. The Midori_String also returns the new value and does not affect the original value, during each method call, so that actual object acts just like a value type.
</p>
<h3> Understanding Chaining Methods after Instantiation </h3>
<p>
Another problem in PHP is that when you instantiate an object,  it does not allow for chaining right away, which can be bothersome.
</p>
<h4>PHP</h4>
<pre class="brush: php;">

	// incorrect way to chain in PHP
	$str = new Midori_String(&quot;don't objectify me, sidekick&quot;)-&gt;concat(&quot;!&quot;); // epoch fail

	// correct way to chain
	$str = new Midori_String(&quot;don't objectify me, sidekick&quot;);
	echo $str-&gt;concat(&quot;!&quot;); // don't objectify me, sidekick!
</pre>
<p>
 So in hopes of getting around that and to use common box types often: I propose creating and using functions &#8220;box_x&#8221; to wrap the instantiation of a box type and to allow for chaining.&#160;  I also thinking having an &#8220;unbox&#8221; function to allow for unboxing of values if the object is an instance of Midori_Nullable, would also be handy.
</p>
<h4>PHP</h4>
<pre class="brush: php;">

	// boxing example with forth coming helper methods
	// these methods are prototypes and would like feed back.

	$str = box_str(&quot;my cool new value&quot;)
		-&gt;replace(&quot;value&quot;, &quot;test&quot;)	//chain 1, replacing a value
		-&gt;toUpper()			// chain 2, uppercasing.
		-&gt;value;				// chain 3, returning the unboxed value

	echo $str; // MY COOL NEW TEST 

 	$str = box_str(&quot;my cool new value!&quot;)-&gt;trimEnd(&quot;!&quot;);
	$unboxed = unbox($str);

	echo $unboxed; // my cool new value!
</pre>
<h3>PHP does not allow for operator operations on objects</h3>
<p> Unfortunately, <a href="http://www.amptools.net/blog/php-lacks-true-object-comparability">PHP does not allow for operator overload on objects like Ruby, C#, and other languages do</a>, so you will have to unbox objects in order to do math routines or apply conditional statements to them. </p>
<pre class="brush: php;">

	// example of what you have to do to add two box objects in PHP
	$grade = new Midori_Int32(90);
	$grade2 = new Midori_Int32(60);

	// correct way to add 2 boxed objects in PHP using Midori
	$sum = unbox($grade) + unbox(grade2);
	$sum = $grade-&gt;value + $grad2-&gt;value;
	echo $sum; // 150

	// incorrect way, though it would be nice if PHP could support it
	$sum = $grade + $grade;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.amptools.net/blog/boxing-and-unboxing-in-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun Times with Partial Loops in Zend Framework</title>
		<link>http://www.amptools.net/blog/fun-times-with-partial-loops-in-zend-framework</link>
		<comments>http://www.amptools.net/blog/fun-times-with-partial-loops-in-zend-framework#comments</comments>
		<pubDate>Thu, 11 Jun 2009 13:45:13 +0000</pubDate>
		<dc:creator>Michael Herndon</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[midori-php]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.amptools.net/?p=87</guid>
		<description><![CDATA[While working with the Zend Framework and partial loops, I ran into a few issues.  One was not getting the data to load, which was easily solved after looking at partials documentation. Make sure you set the object key in the controller for the partial loop. The other issue of trying to pass local [...]]]></description>
			<content:encoded><![CDATA[<img class='gravatar' style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=899a978b0f02774a965aec11eeb0b8f4&amp;default=http://amppotls.net' alt='No Gravatar' width=48 height=48/><p>While working with the Zend Framework and partial loops, I ran into a few issues.  One was not getting the data to load, which was easily solved after looking at <a href="http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.partial" rel="tag">partials documentation</a>. Make sure you set the object key in the controller for the partial loop. The other issue of trying to pass local variables into the partial loop took time to see there was really no current answer without extending or creating a new helper, or the evil global.</p>
<h4>PHP</h4>
<pre class="brush: php;">
// in the action method
global $otherVariable;
$otherVariable = &quot;should be the same through each iteration&quot;;
$this-&gt;view-&gt;partialLoop()-&gt;setObjectKey('model');
$this-&gt;view-&gt;paginator = Zend_Paginator::factory($array); //etc

// in the view
&lt;?= $this-&gt;partialLoop('path/to/_partial.phtml', $this-&gt;paginator) ?&gt;

// in the _partial.phtml
&lt;?php
      $model = $this-&gt;model
      global $otherVariable; // just seems so hackish to have to do this.
?&gt;
</pre>
<p>I have already added a <a href="http://github.com/michaelherndon/midori-php/issues#issue/3">task</a> to <a href="/projects/midori-php" rel="tag">Midori PHP </a> to extend the Partial Loop Helper to overcome the lack of the ability to pass in local variables to the partial loop.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.amptools.net/blog/fun-times-with-partial-loops-in-zend-framework/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>midori php</title>
		<link>http://www.amptools.net/wiki/php-midori</link>
		<comments>http://www.amptools.net/wiki/php-midori#comments</comments>
		<pubDate>Tue, 12 May 2009 06:14:55 +0000</pubDate>
		<dc:creator>Michael Herndon</dc:creator>
				<category><![CDATA[Wiki]]></category>
		<category><![CDATA[midori-php]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.amptools.net/?p=24</guid>
		<description><![CDATA[Midori-PHPÂ is the PHPÂ version of the MidoriÂ Generative Framework. Â Its aim at providing building blocks and springboarding into creating an application. Â 
Midori-Php was created in order to be used with the Zend Framework initially to bring in some rails like concepts as well as help generate the data layer with a type system. Â PHPÂ unfortunately is not a [...]]]></description>
			<content:encoded><![CDATA[<img class='gravatar' style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=899a978b0f02774a965aec11eeb0b8f4&amp;default=http://amppotls.net' alt='No Gravatar' width=48 height=48/><p>Midori-PHPÂ is the PHPÂ version of the MidoriÂ Generative Framework. Â Its aim at providing building blocks and springboarding into creating an application. Â </p>
<p>Midori-Php was created in order to be used with the Zend Framework initially to bring in some rails like concepts as well as help generate the data layer with a type system. Â PHPÂ unfortunately is not a pure object oriented language and lacks core classes similar to what ruby and many other popular languages have to day. Â On top of that problem what types PHP&#8217;s SPL does provide is surely lacking in both power and simple api, instead conforming to keep the terrible naming convention of its functions. Â Â </p>
<h2>Source Code</h2>
<ul>
<li><a href="http://amptools.lighthouseapp.com/projects/30630-midori-php/overview">Project Management  &amp; Tracking</a></li>
<li><a href="http://github.com/michaelherndon/midori-php/tree/master">Midori PHP on GitHub</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.amptools.net/wiki/php-midori/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->