<?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>Aviblock.com &#187; Programming</title>
	<atom:link href="http://www.aviblock.com/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aviblock.com/blog</link>
	<description>My musings on web development</description>
	<lastBuildDate>Thu, 03 Jun 2010 13:40:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Just had my first taste of India&#8230;.</title>
		<link>http://www.aviblock.com/blog/2010/06/03/just-had-my-first-taste-of-india/</link>
		<comments>http://www.aviblock.com/blog/2010/06/03/just-had-my-first-taste-of-india/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 13:40:47 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/?p=102</guid>
		<description><![CDATA[I got to turn this:

&#60;?php $i=1?&#62;
                &#60;?php query_posts&#40;'category_name=Projects2&#38;showposts=3&#38;orderby=rand'&#41;; ?&#62;
                &#60;?php while &#40;have_posts&#40;&#41;&#41; : the_post&#40;&#41;; ?&#62;
&#160;
           [...]]]></description>
			<content:encoded><![CDATA[<p>I got to turn this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;?php</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category_name=Projects2&amp;showposts=3&amp;orderby=rand'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
                <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
      &lt;div class=&quot;set set1&quot;&gt;
	&lt;div class=&quot;title&quot;&gt;&lt;h4&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h4&gt;&lt;/div&gt;
			 &lt;div class=&quot;content&quot;&gt; 
                               &lt;a href=&quot;#&quot;&gt;
                               <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
                               &lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; width=&quot;242&quot; height=&quot;148&quot; alt=&quot;&quot;&gt;
                               &lt;/a&gt; 
		 &lt;!--content end--&gt;&lt;/div&gt;
             &lt;!--set set1 end--&gt;&lt;/div&gt;
&nbsp;
                 <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
                        &lt;div class=&quot;set set1&quot;&gt;
	&lt;div class=&quot;title&quot;&gt;&lt;h4&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h4&gt;&lt;/div&gt;
			 &lt;div class=&quot;content&quot;&gt;
                                &lt;a href=&quot;#&quot;&gt;
                                <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
                                &lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; width=&quot;242&quot; height=&quot;148&quot; alt=&quot;&quot;&gt;
                                &lt;/a&gt; 
			&lt;!--content end--&gt;&lt;/div&gt;
                   &lt;!--set set1 end--&gt;&lt;/div&gt;
&nbsp;
                 <span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
                        &lt;div class=&quot;set set1&quot;&gt;
	&lt;div class=&quot;title&quot;&gt;&lt;h4&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h4&gt;&lt;/div&gt;
			 &lt;div class=&quot;content&quot;&gt;
                                &lt;a href=&quot;#&quot;&gt;
                                <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
                                &lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; width=&quot;242&quot; height=&quot;148&quot; alt=&quot;&quot;&gt;
                                &lt;/a&gt; 
			&lt;!--content end--&gt;&lt;/div&gt;
                   &lt;!--set set1 end--&gt;&lt;/div&gt;
&nbsp;
                 <span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">else</span>
 <span style="color: #009900;">&#123;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
                       &lt;div class=&quot;set set1&quot;&gt;
	&lt;div class=&quot;title&quot;&gt;&lt;h4&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h4&gt;&lt;/div&gt;
			 &lt;div class=&quot;content&quot;&gt;
                                &lt;a href=&quot;#&quot;&gt;
                                <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
                               &lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; width=&quot;242&quot; height=&quot;148&quot; alt=&quot;&quot;&gt;
                                &lt;/a&gt; 
		  &lt;!--content end--&gt;&lt;/div&gt;
                  &lt;!--set set1 end--&gt;&lt;/div&gt;
&nbsp;
                 <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&nbsp;
                   <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
                  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
                  <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_reset_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Into this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category_name=Projects2&amp;showposts=3&amp;orderby=rand'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div class=&quot;set set1&quot;&gt;
	 &lt;div class=&quot;title&quot;&gt;&lt;h4&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h4&gt;&lt;/div&gt;
	 &lt;div class=&quot;content&quot;&gt; 
     &lt;a href=&quot;#&quot;&gt;
     <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
     &lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; width=&quot;242&quot; height=&quot;148&quot; alt=&quot;&quot;&gt;
     &lt;/a&gt; 
  &lt;/div&gt;&lt;!--content end--&gt;
&lt;/div&gt;&lt;!--set set1 end--&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_reset_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Needless to say, my client will no longer be outsourcing to India.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2010/06/03/just-had-my-first-taste-of-india/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Review of the Apostrophe CMS for symfony</title>
		<link>http://www.aviblock.com/blog/2010/04/21/review-of-the-apostrophe-cms-for-symfony/</link>
		<comments>http://www.aviblock.com/blog/2010/04/21/review-of-the-apostrophe-cms-for-symfony/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 02:15:30 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[apostrophe]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/?p=95</guid>
		<description><![CDATA[I know I gave my blessing before to diem, and I&#8217;ll still admit that it is a very good CMS. However, it has always bothered me a little bit just how invasive this CMS is. While it bills itself as a symfony plugin, it is in truth anything but. You must start out using diem, [...]]]></description>
			<content:encoded><![CDATA[<p>I know I gave my blessing before to diem, and I&#8217;ll still admit that it is a very good CMS. However, it has always bothered me a little bit just how invasive this CMS is. While it bills itself as a symfony plugin, it is in truth anything but. You must start out using diem, and then add a little symfony in when you need it.<br />
I was reading, recently, a <a href="http://www.sympalphp.org/blog/the-status-of-sympal-a-call-to-the-community">post</a> on the sympal blog. In this post, Ryan Weaver echoed my latent feelings that a CMS should <em>empower</em> your site with CMS capabilities, but should not take it over completely. In other words, the perfect medium would be in the form of a plugin for symfony 1.x, or bundle perhaps for Symfony 2.x.<br />
There was a <a href="http://www.sympalphp.org/blog/the-status-of-sympal-a-call-to-the-community#comment_39">comment</a> put in there by somebody from the apostrophe team, which made me realize that, apostrophe was perhaps already meeting this goal. Seeing as I needed to pick a new CMS for an upcoming project, I thought I&#8217;d take it for a spin.<span id="more-95"></span><br />
I&#8217;ll start with, what is in my opinion, the basic backbone of what any CMS should be able to do.</p>
<ol>
<li>The first thing, I believe, is managing your websites structure and hierarchy of pages. I don&#8217;t consider this to be the same thing as content, but it is certainly fundamental to a website. Even if your site contains some applications (a blog, a wiki, etc.), there should be a way of shoving them under this rubric, as well.
</li>
<li>The next thing, of course, is managing content. Its not called a <strong>content managment</strong> system for naught, after all. Unfortunately, content is a very overloaded term. Most CMS&#8217;s seem to connect that to your site&#8217;s page structure. Create a page, throw up a WYSIWYG editor, and viola! Some CMS&#8217;s take a more fine grained approach, and consider content in a more abstract light. Content would be comparable to a data structure in a programming language. I believe <a href="http://ez.no/">ezPublish</a> even goes as far as calling content &#8220;classes&#8221;.</li>
<li>Lastly, a CMS should be capable of creating pages which don&#8217;t fall under the rubric of your page structure directly, for example, an article section. You probably don&#8217;t want an entry in your navigation for every single article, but you definitely want a clean url like http://mydomain/articles/this-is-an-article
</li>
</ol>
<p>With that in mind, let&#8217;s talk about the &#8220;theory&#8221; of apostrophe, and how it approaches these scenarios. As far as content, apostrophe seems to have found a ground between the above mentioned approaches. On the one hand, content does not directly equal a page in your site, but <em>can be </em> closely associated with it. On the other hand, content is not relegated to the abstract world of boring data entry forms, but actually real live snippets of html, which can be controlled through boring data entry forms, or an rss feed, or a youtube video, or anything you want if you have some creative ideas.<br />
With apostrophe, the we start out with the concept of a page. A page represents (almost all the time, but we&#8217;ll get to that), a public facing url on your site. Each page is backed by a slug. A page is rendered using standard php + symfony helpers. There is one layout, and each page has a template associated with it. There is no easy way, at the moment, to switch this layout, but there really shouldn&#8217;t be much of a reason why you would have to.<br />
On the layout that comes with apostrophe, are a number of symfony slots, which are filled in at various points by apostrophe. These are generally things like menus or breadcrumbs.<br />
Each page, has more than one &#8220;area&#8221; in it. An area is like a content holder. It can hold various types of content, stacked vertically. Each area has a name and is associated to a page. A template helper is provided to render these areas in your template.<br />
When an area is rendered, and you are logged in with sufficient privileges, you have the ability to add content to this area. These are called slots (not to be confused with symfony slots). There are enough built in slots to put together any run-of-the-mill website fairly easily, and creating custom slots is not terribly difficult. Some of these include, plain text, rich text, video, slideshow, pdf. Each slot comes with a displayable interface (normal mode), and an editing interface (edit mode). The edit mode can be a simple form, or it can be a complex multistep, workflow-engine powered web application (see the image slot). The edit mode is powered by a component called editView. The content for the slots is, wisely, stored as a serialized php array, instead of physical columns in a database table, although the latter is certainly possible if not discouraged. This is somewhat similar to the current trend of NoSQL databases, and somewhat similar to the approach that <a href="http://bret.appspot.com/entry/how-friendfeed-uses-mysql">friendfeed</a> used when scaling their database. It would have been better, in my opinion, to store the information in JSON instead of serialized PHP, or to use an actual NoSQL database, but there is nothing stopping you from implementing your own content slots this way. When the content is not in editing mode, the display is governed by a component called normalView, where you can, of course, massage all your data as you see fit before displaying it in the components template. Each content slot is essentially a module, with two components (editView and normalView), a model class and usually a form as well. This makes it fairly trivial to create custom content slots, especially if you have prior symfony experience.<br />
You also have the option of what is called, under the hood, a singleton area. An area which contains one and only one content slot. There is a special view helper for this as well called a_slot (as opposed to a_area).<br />
By default, each content area is associated with the slug, and therefore the page that its on. In that respect, content and pages are somewhat analogous. For a basic site, this may well give you enough mileage to go. However, the developers realized that there is room for content which is not owned by any particular page, for example, global content. This could be an editable footer or logo which makes its way into the layout. They also recognized that not every page in a website is physically there. They call this concept &#8220;virtual pages&#8221;, and it allows for some very interesting things. Every content area, both infinite and singleton, can be assigned to a &#8220;virtual page&#8221;, and thereby pulled out in any physical page, no matter what slug it has. Virtual pages are distinguished by virtue of not have a leading &#8220;/&#8221; in their slug name, thereby removing them from the realm of the navigation. One use case I came up with, was having a sidebar in the layout, but having the content of the sidebar different for each page. In order to do this, I had to specify a slug that was guaranteed to be unique for each page, so I called it something like &#8220;sidebar-$page->id&#8221;. I will discuss another use case later.<br />
As I mentioned earlier also, a CMS should also be able to handle pages which shouldn&#8217;t exist in your navigation, such as articles. For this, they came up with the concept of engines. Basically, instead of having your page rendered via apostrophe, it gets sent to a regular symfony module, written to certain conventions. You could have an module which renders an article page, based on an id in the url, but this page will still be under the rubric of your site. As an additional bonus, since its a regular symfony module, rendered by a regular symfony template, you can use the apostrophe helpers, and put content areas in a virtual page with a slug derived from the article&#8217;s id. This was the other use case I was referring to earlier.<br />
This cms follows the principle of less is more, and because of that, it is a clean, elegant system, with almost no learning curve.<br />
That is not say it does not have some problems. The admin view requires that the content areas be surrounded by a swath of DIVs. Unfortunately, these DIVs make it into the end user mode. My designer was not so happy to hear that the recommendation was to &#8220;embrace the DIVs&#8221;.<br />
Also, the page gets loaded with a lot of incoherent, redundant, inline javascript. Both inline in the page, and sometimes inlined on the element itself. There is no Javascript framework such as what comes with diem. For example, when you click &#8220;add slot&#8221; in an area, you are greeting with a very eye-appealing dropdown box. Unfortunately, to mimic that behavior seems to require a lot of copy and pasting.<br />
Certain areas of the code also look suspect and &#8220;hackish&#8221; to me. Any class named &#8220;aTools&#8221; with only static methods is certainly a red flag. Of course, symfony 1.x also has code like this as well, but that doesn&#8217;t mean that bad habits should be copied. Virtual pages are implemented, by temporarily switching a global variable (disguised a static variable), which holds the current page&#8217;s slug, for the duration of the rendering, until when the global variable is swapped back to its original state. This feels like hacky code to me.<br />
Over all, I have to certainly commend the developers of apostrophe. They managed to come up with good solutions for some classic problems in web development. They managed to create a tool which is good for end users *and* developers at the same time. Certainly not an easy task.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2010/04/21/review-of-the-apostrophe-cms-for-symfony/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The end of the PHP vs Template language debate?</title>
		<link>http://www.aviblock.com/blog/2010/02/10/the-end-of-the-php-vs-template-language-debate/</link>
		<comments>http://www.aviblock.com/blog/2010/02/10/the-end-of-the-php-vs-template-language-debate/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 03:36:39 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xhp]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/?p=92</guid>
		<description><![CDATA[For years there has been a ferocious debate about whether it is better to abstract away HTML creation with PHP by using a template language, or whether we should stick with PHP itself as the template language. I always thought the best way to go was a with a hybrid. A templating language which resembles [...]]]></description>
			<content:encoded><![CDATA[<p>For years there has been a ferocious debate about whether it is better to abstract away HTML creation with PHP by using a template language, or whether we should stick with PHP itself as the template language. I always thought the best way to go was a with a hybrid. A templating language which resembles XML, sort of like what you get with JSTL. There have been <a href="http://phptal.org/">some</a> <a href="http://flow3.typo3.org/documentation/manuals/fluid/">attempts </a>, which have been pretty good. Facebook, however, just took this <a href="http://www.facebook.com/notes/facebook-engineering/xhp-a-new-way-to-write-php/294003943919">one step further</a>, and integrated XML into PHP with XHP. This is sort of reminicient of <a href="http://blogs.msdn.com/jimoneil/archive/2009/06/15/x-is-for-xml-literal.aspx">XML Literals</a> in VB. They have released the code on <a href="http://github.com/facebook/xhp">github</a> already. The best part about it is that every XML element is represented by a class, leaving room to create sophisticated widgets out of XML tags! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2010/02/10/the-end-of-the-php-vs-template-language-debate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diem, my new CMS of choice</title>
		<link>http://www.aviblock.com/blog/2010/01/04/diem-my-new-cms-of-choice/</link>
		<comments>http://www.aviblock.com/blog/2010/01/04/diem-my-new-cms-of-choice/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 17:57:30 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cmf]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[diem]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/?p=89</guid>
		<description><![CDATA[Every since I started getting frustrated with Expression Engine, I was always looking out for something different. A CMS aimed at developers. Just about every CMS on the market is aimed at letting less technical people get out their and create content. There are a few CMSs that bill themselves as a Content Management Framework. [...]]]></description>
			<content:encoded><![CDATA[<p>Every since I started getting frustrated with Expression Engine, I was always looking out for something different. A CMS aimed at developers. Just about every CMS on the market is aimed at letting less technical people get out their and create content. There are a few CMSs that bill themselves as a Content Management <em>Framework</em>. In other words, they provide with the tools to create your own custom CMS. In fact, I would actually put Expression Engine in that category. Others that come to mind are Drupal and EzPublish. Both of these, for some reason, I was never able to wrap my head around. Then again, I never spent much time with them either. Drupal is written procedurally (at least they admit it) which is not my style. Something always goes wrong when I try to install EzPublish.<br />
Then of course there is the option of <a href="http://gadgetopia.com/post/5940">RDBMSWAAS</a>. When thinking about that last option, there are two frameworks that come to mind, Symfony, and Django. I tried Django before for a small project, and it worked out well, but I had never really given Symfony the time of day. When looking at the Symfony website, I stumbled across a nice hidden gem.<span id="more-89"></span><br />
That gem is called <a href="http://diem-project.org/blog">Diem</a>, and it is a CMF written on top Symfony, masquerading as a plugin. Out of the box it can do some pretty cool stuff, which all boil down to placing intelligent widgets on your page, which strikes me as the cleanest way to make a webpage with some dynamic features on it, or even a full blown web app.<br />
What does Diem add to Symfony? Out-of-the-box, Symfony is probably the most &#8220;modular&#8221; of all PHP frameworks. Its modularity rings heavily of Django. It happens to be super easy to create distributable mini-applications. A symfony project is made up of applications, and each application is made up of modules. The project, applications and the modules within the application all follow a similar structure for configuration which makes for nice &#8220;cascading effect&#8221;, whereas an app contain override configuration from the project, and a module can override configuration from an app (and the project of course). Not only that but you can merge two different configurations from a module provided by a plugin and your own local version of that. This, we&#8217;ll see, can make for some nice extensibility.<br />
My biggest gripe with the framework, and it really is not a fault of its own, but probably of Symfony, is the blatant misuse of inheritance. There are certain components which have inheritance hierarchies running 4 or 5 levels deep. I have not yet gone through the whole framework, but I have not encountered an Interface in any of the core components, such as the front controller, and the router. This kind of encourages extensibility via subclassing, as opposed to implementing interfaces. Hopefully Symfony 2.0 will alleviate some of this.<br />
That being said, the best part of Diem is the extensibility. By virtue of the fact that it is written on top of Symfony, you have some good extensibility built in right away. Many core components can be swapped out using factories.yml, and the core Diem components (which are already replacing the symfony ones), are no exception to this.<br />
As I explore the framework, I&#8217;m trying to make a series of posts on Diem can be extended and modified, including some (at least for now) undocumented features that I&#8217;ve discovered.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2010/01/04/diem-my-new-cms-of-choice/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Quick code review of Expression Engine 2.0</title>
		<link>http://www.aviblock.com/blog/2009/12/29/quick-code-review-of-expression-engine-2-0/</link>
		<comments>http://www.aviblock.com/blog/2009/12/29/quick-code-review-of-expression-engine-2-0/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 22:55:08 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/?p=87</guid>
		<description><![CDATA[I just got a hold of the public beta of Expression Engine 2.0. I have been using Expression Engine 1.x for a number of years now, and I&#8217;ll admit, I wasn&#8217;t the most experienced PHP programmer at the time. It was probably the first large PHP program that I had ever used, and I was [...]]]></description>
			<content:encoded><![CDATA[<p>I just got a hold of the public beta of Expression Engine 2.0. I have been using Expression Engine 1.x for a number of years now, and I&#8217;ll admit, I wasn&#8217;t the most experienced PHP programmer at the time. It was probably the first large PHP program that I had ever used, and I was a little bit awed at how such a massively big OO program could be written.<br />
Since then, I&#8217;ve improved my skills tremendously. I&#8217;ve learned about SOLID, and DRY. Dependency Injection and Test driven design. I&#8217;ve learned about domain modeling, and proper OO design. The code in EE 1.x is utter crap, of course! Global variables scattered everywhere. Copy &#038; Paste style coding. Non-resuable components. No coherent API to speak of. Purely designed plugin system. Who could blame them, though. The code was written almost 10 years ago, in PHP4&#8211;with no intention of dropping PHP4 support.<br />
I think I first heard about EE 2.0 almost two years ago. It was coming out <em>that</em> summer. Ever little bit of news that came out made me a little more gittier. It was going to be built on Code Igniter, an MVC framework. Boy was I suprised.<span id="more-87"></span><br />
I don&#8217;t have time to review the whole code, but suffice it to say, its basically the old EE code, with a few minor differences. I think the following comment sums up all the problems:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/**
 * CodeIgniter Application Controller Class
 *
 * This class object is the super class the every library in
 * CodeIgniter will be assigned to.</span></pre></div></div>

<p>Of course this is really CodeIgniter&#8217;s problem I guess, but it certainly bleeds into EE. This is called a God object, and is one of the oldest anti-patterns in the book. No more global variables they say? Gone is global $TMPL. Long live $this->EE->TMPL! What about dependency injection? We&#8217;re almost in 2010 for god sakes. This reminds me of the &#8220;let&#8217;s get rid of globals but making a bunch of singleton and static classes&#8230;now we&#8217;re doing OOP, yeah!&#8221; argument.<br />
At least the template class can be used, more or less, &#8220;outside&#8221; of EE templates, but so far that&#8217;s the only &#8220;api&#8221; improvement I could find. They haven&#8217;t gotten rid of such garbage such as &#8220;action_ids&#8221;. The database is still retarded. Not only are they storing settings in the database, they&#8217;re now encoding them in base64! Where did that come from?.</p>
<p>Ultimately, I am utterly disappointed, and EE is becoming less and less of a platform to build applications off of.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2009/12/29/quick-code-review-of-expression-engine-2-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CQRS (Command and Query Responsibility Segregation) in PHP</title>
		<link>http://www.aviblock.com/blog/2009/12/10/cqsr-in-php/</link>
		<comments>http://www.aviblock.com/blog/2009/12/10/cqsr-in-php/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 20:57:54 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[command query separation]]></category>
		<category><![CDATA[ddd]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/?p=82</guid>
		<description><![CDATA[It always seems to me that the PHP world is one step behind the current trends in the &#8220;enterprise world&#8221;. For example, Rails popularized the &#8220;ActiveRecord&#8221; pattern a few years ago. Ever since then, there has been an explosion of ActiveRecord implementations in PHP. Many even mistakenly refer to them as an &#8220;ORM&#8221;, but I [...]]]></description>
			<content:encoded><![CDATA[<p>It always seems to me that the PHP world is one step behind the current trends in the &#8220;enterprise world&#8221;. For example, Rails popularized the &#8220;ActiveRecord&#8221; pattern a few years ago. Ever since then, there has been an explosion of ActiveRecord implementations in PHP. Many even mistakenly refer to them as an &#8220;ORM&#8221;, but I won&#8217;t beat a dead horse here. ActiveRecord is great for your basic run-of-the-mill address book/cookbook/blog type of app, where it basically data driven, and there&#8217;s not much &#8220;business logic&#8221; to go around. For the majority of PHP applications out there, these tools are a god send.<br />
As PHP matures, especially the object model, advanced developers have started to realize the limits of this pattern. Now the big rage is the DataMapper pattern, and DDD. We try to separate out the domain of application, and the holy grail is now transparent persistence. With great tools like Doctrine 2.0 and Object_Freezer, both of which are only possible with the new additions in PHP 5.3, these dreams are becoming a reality.<br />
<span id="more-82"></span><br />
With this approach, which I have tried to follow recently, there are a couple of pointed issues. The biggest is displaying your domain objects. Off the bat, we don&#8217;t want to &#8220;pollute&#8221; our domain with display concerns (although one could argue that displaying the object is a business concern). So if we want to &#8220;drag the data&#8221; out of our domain, we need a lot of ugly &#8220;getters&#8221;, or to leverage the __get magic method. Getters have long been shunned for breaking encapsulation, revealing the &#8220;shape&#8221; of an entity (ie., it should not be so important to us that a customer has a first name), and some other things that don&#8217;t really apply in PHP land. But besides all that, they&#8217;re just so annoying to write.<br />
Additionally, we don&#8217;t necessarily want to have our domain objects show up in our UI like that. The domain objects are not tailored made for consumption of our UI. There are many different presentation concerns such as, what I call the &#8220;Fowler Conundrum&#8221;, where do you specify that negative balances will show up in red, and positive in black? Do you create views which have all this ugly logic in them? Do you add it to your domain? Do you create a view helper for every little presentation concern? What about date formatting. Do you need to bring in a DateTime object in your view, and clutter it up with date formatting code? What if you only need a handful of fields to display&#8230;do we throw in the whole object to the UI and hope for the best?<br />
The answer to this is to add an additional layer. The ViewModel. The ViewModel is shaped for every view in your UI. It contains all the necessary presentation logic.<br />
The question still begs, how do you create these ViewModels? There&#8217;s basically three choices. Getters, displaying to an interface, and using Reflection. All of these feel like you&#8217;re compromising somewhere.<br />
Another problem that I came up with recently is, how do you manage something like an autocomplete field. An autocomplete field takes the letters which have been typed in, and searches the database. So do I now need to search the database, get a bunch of domain objects, translate them in a ViewModel and send it back to the UI?<br />
How about pagination? For efficiency purposes, we obviously want to paginate on the query level. We don&#8217;t want to bring in all our information, and then paginate that&#8230;it defeats (most of) the purpose. So do we have to pollute our repositories with findByPage methods? The other solution is almost as ugly (but it has a lot of elegance to it). In the .NET world, a proposed solution was to return an IQueryable&#8230;an interface that LINQ understands. The idea is, you&#8217;re repository returns an IQueryable (or even better, a special subset of IQueryable that you can call IPageable), and once you get that, you construct the rest of the information as gotten from the ui. This was debated upon for a long time whether 1) Whether this constitutes &#8220;pure DDD&#8221; and 2) Whether it is a good practice to begin with. The PHP version of this could be to return a Zend_Paginator_Adapter_Interface and basically do the same thing.<br />
The latest &#8220;trend&#8221;, of which I don&#8217;t really see anybody speaking about in the PHP world, is that of CQRS. CQRS stands for Command and Query Responsibility Segregation, and it was formally known as CQS, or command query separation. CQS is a basic tenet of OOP, put forth by Bertand Meyer. The idea is simple, every method on an object is either a command (ie., it does something), or it is a query (ie., it retrieves information). A method should not do both (Martin Fowler admits that there are some compelling reasons to violate this, like popping a value from a stack, but in that case, the convenience outweighs the strict and blind adherence to principles).<br />
In the past year of so, this pattern has been expanded on an architectural level. Meaning commands go to the domain, and queries go somewhere else. There are two parts of your system. The commands, which tell your system to do something, and the queries. The queries come from a query repository, which is a stale snapshot of the state of your entities. The commands go to a domain repository, which publish an internal event (which captures the business intent of the command), and an external event to update the data store.<br />
The beauty of this, is that your view models don&#8217;t come from your domain anymore. They come from your query repository. You could retrieve them anyway you want (ORM, TableDataGateway, ActiveRecord or even straight SQL). In fact, the various views on your data could actually be real views in your database, denormalized to flatten relationships, or with only the fields that you need. Also, the internal published events can be stored in an EventStore, and played back to maintain the current state of the entity. This removes almost entirely the &#8220;impendence mismatch&#8221; between objects and the relational database.<br />
I will hopefully right more on this pattern, and how it can be applied to PHP, as I learn more about it myself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2009/12/10/cqsr-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Alternative to Zend_Form ViewScript decorator</title>
		<link>http://www.aviblock.com/blog/2009/11/29/alternative-to-zend_form-viewscript-decorator/</link>
		<comments>http://www.aviblock.com/blog/2009/11/29/alternative-to-zend_form-viewscript-decorator/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 16:34:04 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ViewScript decorator]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Form]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/?p=79</guid>
		<description><![CDATA[Zend_Form is great for prototyping forms. It takes a lot of the drudge work out, and makes forms easily &#8220;reusable&#8221;. The decorator system, which is admittedly a little scary for the uninitiated, is actually very powerful. I&#8217;m suer that eventually, however, we&#8217;ve all reached that point. The point where you spend more time configuring the [...]]]></description>
			<content:encoded><![CDATA[<p>Zend_Form is great for prototyping forms. It takes a lot of the drudge work out, and makes forms easily &#8220;reusable&#8221;. The decorator system, which is admittedly a little scary for the uninitiated, is actually very powerful. I&#8217;m suer that eventually, however, we&#8217;ve all reached that point. The point where you spend more time configuring the form to do what you want, then actually doing something with it.<span id="more-79"></span><br />
This is especially more important when working with talented designers who know their HTML/CSS, and know exactly what theywant to do with the form. Trying to mangle the form to do what they want in that case is generally a waste of time. It also makes it much harder for the designer to apply his CSS magic. You might look and smile at how beautiful <?=$this->form?> looks, abstracting away all you hard work. However the designer will likely have to see the generated html to get an understanding of the structure. Want to add a CSS class? Good luck.<br />
Eventually, we discover the ViewScript decorator. Although the code in that viewscript can be a bit complex, we once again have panacea. The designer gets a viewscript with which he can muck around. You get to set one or two decorators and we&#8217;re back to <?=$this->form?> again.<br />
How does the ViewScript decorator work? The workhorse of it involves setting up a partial, and pushing in to the &#8220;model&#8221; of the partial, the form under the alias &#8220;element&#8221;. Now, anybody who&#8217;s read the Zend Framework performance guide, will have noticed that use of partials is somewhat discouraged. To create a partial, it involves cloning Zend_View, and is somewhat of an unneeded overhead.<br />
So is there an an alternative? It hit me today, that there&#8217;s absolutely nothing wrong with just outputting the form in the viewscript it self. Instead of:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderViewHelper</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/form&gt;</pre></div></div>

<p>In a form ViewScript, just output that directly into your viewscript!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderViewHelper</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/form&gt;</pre></div></div>

<p>If you want the script to be reusable, just use the render viewhelper, as recommended in the performance guide.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2009/11/29/alternative-to-zend_form-viewscript-decorator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making Zend_Auth more &#8220;Object Oriented&#8221;</title>
		<link>http://www.aviblock.com/blog/2009/10/29/making-zend_auth-more-object-oriented/</link>
		<comments>http://www.aviblock.com/blog/2009/10/29/making-zend_auth-more-object-oriented/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 01:12:56 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[tell don't ask]]></category>
		<category><![CDATA[zend_auth]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/?p=70</guid>
		<description><![CDATA[Recently Giorgio Sironi wrote a post on Zend_Auth. When I saw the title, I was expecting something along the lines of most of his posts, which have been discussing many OO topics. The content was rather disappointing, and I&#8217;ll tell you why.

Especially coming from Giorgio, who strikes me as an OO purist, and a big [...]]]></description>
			<content:encoded><![CDATA[<p>Recently <a href="http://giorgiosironi.blogspot.com">Giorgio Sironi</a> wrote a post on <a href="http://giorgiosironi.blogspot.com/2009/10/php-login-with-zendauth.html">Zend_Auth</a>. When I saw the title, I was expecting something along the lines of most of his posts, which have been discussing many OO topics. The content was rather disappointing, and I&#8217;ll tell you why.<br />
<span id="more-70"></span><br />
Especially coming from Giorgio, who strikes me as an OO purist, and a big fan of <a href="http://misko.hevery.com/">Misko Hevery</a>, the content was rather disappointing. The big problem with Zend_Auth, is that it is not Object Oriented&#8230;or at least not the way it&#8217;s depicted in the documentation. </p>
<p>Let&#8217;s take a classic procedural app, like&#8230;I don&#8217;t know&#8230;Wordpress. </p>
<p>The wordpress API has a function wp_authenticate_username_password, which will authenticate a user, with a given username and password. So, if you had an app which you wanted to connect with Wordpress (or maybe write some kind of extension or plugin), you can easily make use of this API. It&#8217;s very easy to understand, and there&#8217;s nothing inherently wrong with it. </p>
<p>Let&#8217;s translate this to Zend_Auth. Or to be more accurate, to Zend_Auth_Adapter_Interface:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> authenticateAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//Set up adapter</span>
    <span style="color: #000088;">$adapter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIdentity</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$identity</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$adapter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCredential</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$credential</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">adapter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//Do other stuff</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Look&#8217;s good right? We&#8217;re using an object (Zend_Auth_Adapter_Interface), in an object (LoginController), and returning an object (Zend_Auth_Result). What can be more &#8220;Object Oriented&#8221; about that?</p>
<p>For a long time this smelled to me, and I couldn&#8217;t stand looking at my auth controller. I knew there had to be a better way. So after a lot of thought, pondering, reading, and <a href="http://misko.hevery.com/2009/07/31/how-to-think-about-oo/">inspiration</a>, this is what I&#8217;ve come with. </p>
<p>The first thing to notice is that all we&#8217;ve done was call bunch of methods. These could have easily been static methods, or even global functions like in Wordpress&#8217;s API. The second sin here, is all these calls make our controller nice and <a href="http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model">fat</a>. To make matters worse, it makes it hard to reuse this authentication logic somewhere else. Imagine if you were writing a CMS, and somebody wanted to write an extension, using your API (try authenticating a user using <a href="http://www.expressionengine.com">Expression Engine</a>&#8217;s &#8220;API&#8221;).</p>
<p>What did we really want to do though? Authenticate a user of course.</p>
<p>How about something like this?</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> authenticateAction<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000000; 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;">$user</span> <span style="color: #339933;">===</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
          <span style="color: #666666; font-style: italic;">//somehow get the user, probably from a form submission...</span>
     <span style="color: #009900;">&#125;</span>     
     <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$authenticationService</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$authenticationService</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here we are delegating our business to logic to the&#8230;um&#8230;business layer. There are other advantages here, though.  The user class doesn&#8217;t have to spill his beans to the controller, in keeping with the principle of <a href="pragprog.com/articles/tell-dont-ask">tell don&#8217;t ask.</a><br />
So what are the bits and pieces here?<br />
The first is obvious&#8230;the user class. That just needs a reference to an authenticator. So what is an authenticator? It could be as simple as passing in an instance of Zend_Auth_Adapter_Interface.<br />
But I like to go one level more abstract, and create my own interface for authentication. My default implementation will be a ZendAuthenticator. To make things simple, my implementation will have a hard dependency on Zend_Auth_Adapter_DbTable, and not on the interface for the adapter. I have a couple of reasons for this: 90% of all web apps authenticate a database. The chances of them switching to something else, are not high. Certainly not mine.<br />
Also, in general I don&#8217;t like the Zend_Auth_Adapter_Interface. It seems to me that it violates one of Misko&#8217;s rules that <a href="http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/">injectables can depend on injectables, and newables can depend on newables, but the twain shall not mix</a>.<br />
So if my understanding of that rule is correct, $adapter->setIdentity($thisvarisanewable), would be a violation of the rule. And indeed, you can see that to switch adapters would be a big pain. Each adapter is required to be &#8220;setup&#8221; before calling its authenticate method, and they have wildly different APIs. (Of course, I&#8217;ve been trying to think all day how they can all be unified better, and I appreciate that it&#8217;s not an easy thing. So let&#8217;s just keep it simple (ok, not that simple)).<br />
So my interface looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">interface</span> Authenticator <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">/* @returns Zend_Auth_Result */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> authenticate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> login<span style="color: #009900;">&#40;</span><span style="color: #000088;">$identity</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I split up login and identity, because it entirely desirable at some point to log in a user without having to authenticate him (think &#8220;log in as user&#8221; for an admin).</p>
<p>(I&#8217;ve been back and forth on whether these should really be two different classes, since there are two responsibilities here, if anybody has some recommendations.)</p>
<p>My implementation looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ZendAuthenticator implements IAuthenticator <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$adapter</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>Zend_Auth_Adapter_DbTable <span style="color: #000088;">$adapter</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">adapter</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$adapter</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> authenticate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$identity</span><span style="color: #339933;">,</span><span style="color: #000088;">$credential</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">adapter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIdentity</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$identity</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">adapter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCredential</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$credential</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">adapter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> login<span style="color: #009900;">&#40;</span><span style="color: #000088;">$identity</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Zend_Auth<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStorage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$identity</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> Zend_Auth<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIdentity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>(Another point to think about here: ignoring Zend_Auth completely, and just using Zend_Session_Namespace. I&#8217;m not sure exactly what Zend_Auth is gaining me here. It seems like the real gain here is from the adapter.)</p>
<p>Now my controller doesn&#8217;t smell as bad, and is much more of a pleasure to look at.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2009/10/29/making-zend_auth-more-object-oriented/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing PATH_INFO on bluehost and other shared hosts</title>
		<link>http://www.aviblock.com/blog/2009/08/07/fixing-path_info-on-bluehost-and-other-shared-hosts/</link>
		<comments>http://www.aviblock.com/blog/2009/08/07/fixing-path_info-on-bluehost-and-other-shared-hosts/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 19:54:43 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cgi.fix_pathinfo]]></category>
		<category><![CDATA[Expression Engine]]></category>
		<category><![CDATA[ORIG_PATH_INFO]]></category>
		<category><![CDATA[PATH_INFO]]></category>
		<category><![CDATA[php.ini]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/?p=66</guid>
		<description><![CDATA[The first time I setup an Expression Engine site on bluehost, and removed the index.php file via the .htaccess file, I ran into a problem where every template was redirecting back to the main index template. At the time, I traced this down to fact that the &#8220;segments&#8221; were not getting populated properly.
A brief search [...]]]></description>
			<content:encoded><![CDATA[<p>The first time I setup an Expression Engine site on bluehost, and removed the index.php file via the .htaccess file, I ran into a problem where every template was redirecting back to the main index template. At the time, I traced this down to fact that the &#8220;segments&#8221; were not getting populated properly.<br />
A brief search led to the EE wiki, which advocated swapping out PATH_INFO for ORIG_PATH_INFO. Although not being a fan of hacking core stuff, I was kind of cornered into this, so I went for it. This has been my running solution for the past two years.<br />
Recently, I ran into an issue where the $_SERVER['PHP_SELF'] was not returning anything after the file name. In other words, for http://mysite/foo.php/bar, PHP_SELF should be equal to foo.php/bar.<br />
I spoke with my host about it (a similar host to bluehost), and they said to put the following in the php.ini file: cgi.fix_pathinfo=Off<br />
After, I did this, PHP_SELF worked fine. Unfortunately, I ran into a similar situation like I described at the outset. Then it hit me&#8230;I changed ORIG_PATH_INFO back to PATH_INFO and&#8230;it worked!<br />
So now I listed this as another potential solution in the EE wiki.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2009/08/07/fixing-path_info-on-bluehost-and-other-shared-hosts/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The joys of the command line</title>
		<link>http://www.aviblock.com/blog/2009/07/13/the-joys-of-the-command-line/</link>
		<comments>http://www.aviblock.com/blog/2009/07/13/the-joys-of-the-command-line/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 13:50:26 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/2009/07/13/the-joys-of-the-command-line/</guid>
		<description><![CDATA[I&#8217;ve always loved the unix command line and its power. I recently found the website http://www.commandlinefu.com which people can submit their own command line goodies. This really shows off the power of the command line!
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always loved the unix command line and its power. I recently found the website <A href="http://www.commandlinefu.com">http://www.commandlinefu.com</a> which people can submit their own command line goodies. This really shows off the power of the command line!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2009/07/13/the-joys-of-the-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
