<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Creating a routing-based menu in symfony 1.2, part 3: the builder</title>
	<atom:link href="http://blog.vworld.at/2009/04/03/creating-a-routing-based-menu-in-symfony-12-part-3-the-builder/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.vworld.at/2009/04/03/creating-a-routing-based-menu-in-symfony-12-part-3-the-builder/</link>
	<description>Software development and software quality</description>
	<lastBuildDate>Thu, 17 Jun 2010 20:00:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: David</title>
		<link>http://blog.vworld.at/2009/04/03/creating-a-routing-based-menu-in-symfony-12-part-3-the-builder/comment-page-1/#comment-1823</link>
		<dc:creator>David</dc:creator>
		<pubDate>Sat, 04 Apr 2009 12:31:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vworld.at/?p=112#comment-1823</guid>
		<description>Thanks for your input, I will include this in the final version. For the same reason I inject the routing information into the sfMenuItem objects, but of course the context should also be injected.</description>
		<content:encoded><![CDATA[<p>Thanks for your input, I will include this in the final version. For the same reason I inject the routing information into the sfMenuItem objects, but of course the context should also be injected.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hugo</title>
		<link>http://blog.vworld.at/2009/04/03/creating-a-routing-based-menu-in-symfony-12-part-3-the-builder/comment-page-1/#comment-1822</link>
		<dc:creator>Hugo</dc:creator>
		<pubDate>Sat, 04 Apr 2009 09:40:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.vworld.at/?p=112#comment-1822</guid>
		<description>Hello,

That&#039;s a great serie of symfony articles but there is one bad practice you show. You shouldn&#039;t have to call the context inside your class but pass it from the outside. The problem is that calling sfContext::getInstance() inside a classe evolves a string coupling with your class and avoid it to be unit tested... The solution is to create a getter and a setter to pass the context from outside the class.

&lt;pre lang=&quot;php&quot;&gt;
  public function setContext($context)
  {
    $this-&gt;context = $context;
  }

  public function getContext()
  {
    return $this-&gt;context;
  }

  // ...
}
&lt;/pre&gt;

You can also pass the context as a constructor argument.

++</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>That&#8217;s a great serie of symfony articles but there is one bad practice you show. You shouldn&#8217;t have to call the context inside your class but pass it from the outside. The problem is that calling sfContext::getInstance() inside a classe evolves a string coupling with your class and avoid it to be unit tested&#8230; The solution is to create a getter and a setter to pass the context from outside the class.</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> setContext<span style="color: #009900;">&#40;</span><span style="color: #000088;">$context</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;">context</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$context</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> getContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">context</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You can also pass the context as a constructor argument.</p>
<p>++</p>
]]></content:encoded>
	</item>
</channel>
</rss>
