<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Eat my monkeydust</title>
	
	<link>http://eatmymonkeydust.com</link>
	<description>Life, PHP and Symfony - straight from the monkey's mouth</description>
	<lastBuildDate>Fri, 07 Oct 2011 14:00:19 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/EatMyMonkeydust" /><feedburner:info uri="eatmymonkeydust" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Optimising a PHP (symfony 1.x/Doctrine 1.x) application</title>
		<link>http://feedproxy.google.com/~r/EatMyMonkeydust/~3/HRMwd8XMfTA/</link>
		<comments>http://eatmymonkeydust.com/2011/10/optimising_a_php_symfony_doctrine_application/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 13:59:40 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=305</guid>
		<description><![CDATA[Introduction Whilst everyone is buzzing and creating fancy new Symfony2/Doctrine 2 applications, and perhaps even a shift to new frameworks/no frameworks, a great deal of us are still maintaining legacy apps and will be for some time to come. As these apps grow, we occasionally need to look back and scream at our old code [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Whilst everyone is buzzing and creating fancy new Symfony2/Doctrine 2 applications, and perhaps even a shift to new frameworks/no frameworks, a great deal of us are still maintaining legacy apps and will be for some time to come. As these apps grow, we occasionally need to look back and scream at our old code and wonder why we didn&#8217;t make it more scalable or use neat optimisation tricks back when it was first conceived. The fact is, many of these &#8220;tricks&#8221; are not necessary at the time for a virgin app, and we need to develop code that is relevant to the task at hand.</p>
<p>That said, being aware of some of the case studies I will present to you now may help you to optimise old code, but may also allow you to think twice when you are working with new code &#8211; as the things I will describe do not take too much time to implement first time round.</p>
<p>Read the full article over at <a href="http://elephpants.blog.redpill-linpro.com/2011/10/07/optimising_a_php_symfony_doctrine_application-2/" title="the Redpill Linpro "ElePHPhants blog"">the Redpill Linpro &#8220;ElePHPhants blog</a></p>
<img src="http://feeds.feedburner.com/~r/EatMyMonkeydust/~4/HRMwd8XMfTA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2011/10/optimising_a_php_symfony_doctrine_application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://eatmymonkeydust.com/2011/10/optimising_a_php_symfony_doctrine_application/</feedburner:origLink></item>
		<item>
		<title>Redpill Linpro and Varnish software, Gold sponsors of Symfony Live (Paris) 2011</title>
		<link>http://feedproxy.google.com/~r/EatMyMonkeydust/~3/daCjMfwauqM/</link>
		<comments>http://eatmymonkeydust.com/2011/01/redpill-linpro-and-varnish-software-gold-sponsors-of-symfony-live-paris-2011/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 11:26:18 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[conferences]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=284</guid>
		<description><![CDATA[Introduction As a Symfony user and contributor for several years, it gives me great pleasure to announce that the company I work for Redpill Linpro along with sister company Varnish Software have agreed to be gold sponsors of the Symfony Live conference in Paris (March 2011). As a company we have benefited from the Symfony [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://eatmymonkeydust.com/wp-content/uploads/2011/01/redpill_linpro_varnish.png"><img class="size-full wp-image-285 alignright" style="border: 0pt none;" title="redpill_linpro_varnish" src="http://eatmymonkeydust.com/wp-content/uploads/2011/01/redpill_linpro_varnish.png" alt="" width="231" height="153" /></a></p>
<h2>Introduction</h2>
<p>As a Symfony user and contributor for several years, it gives me great pleasure to announce that the company I work for <a href="http://redpill-linpro.com" target="_blank">Redpill Linpro</a> along with sister company <a href="http://varnish-software.com" target="_blank">Varnish Software</a> have agreed to <strong><span style="color: #ff6600;">be gold sponsors</span></strong> of the <a href="http://www.symfony-live.com/paris" target="_blank">Symfony Live conference in Paris</a> (March 2011).</p>
<p>As a company we have benefited from the Symfony framework in many ways including:</p>
<ul>
<li>Rapid development</li>
<li>Consistency (easy to bring team members in and out)</li>
<li>Community support</li>
<li>Great documentation</li>
</ul>
<p>And given back by providing time for our developers to:</p>
<ul>
<li>File bug reports</li>
<li>Submit patches</li>
<li>Develop plugins</li>
<li>Help other users (particularly in IRC and the Symfony Forum)</li>
<li>Update the documentation</li>
</ul>
<p>By agreeing to <strong><span style="color: #ff6600;">gold sponsorship</span></strong> we are now also making a small financial contribution to the project, whilst at the same time giving ourselves a chance to become more known in the Symfony world, especially with <a href="http://symfony-reloaded.org/" target="_blank">Symfony2</a> just around the corner and its great support for Varnish!</p>
<h2>Brief history of the companies</h2>
<p>Until recently, Redpill and Linpro were two separate companies, and the work done by Varnish Software was a part of Linpro. In 2008, Linpro and Redpill merged to form Redpill Linpro, and in 2010 Varnish Software broke away to form a &#8220;daughter&#8221; company and concentrate on the Varnish cache. Confused?</p>
<p>The most important thing is that all of the companies involved are dedicated to open source, you can read more about <a href="http://redpill-linpro.com/About-us" target="_blank">Redpill Linpro</a> and <a href="http://www.varnish-software.com/about" target="_blank">Varnish Software</a> on their respective web sites.</p>
<h2>Employment Opportunities for Symfony developers in &#8220;the North&#8221;</h2>
<p>If you are looking for a company to work for with a strong PHP team, and either already live in or are considering a move to &#8220;the Nordic region¹&#8221; please get in touch. We also have opportunities for Java developers and <a href="http://redpill-linpro.com/Grow-with-us/Who-are-we-looking-for" target="_blank">various other posts</a> related to Open Source technologies, and if we don&#8217;t have a specific post for you but you are a skilled open source enthusiast, we are also interested in your CV &#8211; who knows, we might be able to create one for you.</p>
<p>¹We have offices in Norway, Sweden, Denmark and Finland, the bulk of Symfony operations are presently in Oslo.</p>
<img src="http://feeds.feedburner.com/~r/EatMyMonkeydust/~4/daCjMfwauqM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2011/01/redpill-linpro-and-varnish-software-gold-sponsors-of-symfony-live-paris-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://eatmymonkeydust.com/2011/01/redpill-linpro-and-varnish-software-gold-sponsors-of-symfony-live-paris-2011/</feedburner:origLink></item>
		<item>
		<title>Doctrine 2 table prefixes with many-to-many relations</title>
		<link>http://feedproxy.google.com/~r/EatMyMonkeydust/~3/BrtsAc0JKvY/</link>
		<comments>http://eatmymonkeydust.com/2010/11/277/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 15:44:14 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=277</guid>
		<description><![CDATA[&#8220;We recently had to implement table prefixes on our tables in Doctrine 2, which turned out to be not so trivial, and led me to a journey inside the Doctrine 2 metadata parser, event hooks and relation mapper. Fun stuff!&#8221; Read the full article by Daniel Andrè Eikeland on the Redpill Linpro PHP Competence Group [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;We recently  had to implement table prefixes on our tables in Doctrine 2, which  turned out to be not so trivial, and led me to a journey inside the  Doctrine 2 metadata parser, event hooks and relation mapper. Fun stuff!&#8221;</p>
<p>Read the full article by Daniel Andrè Eikeland on the <a href="http://elephpants.blog.linpro.no/2010/11/25/doctrine-2-table-prefixes-with-many-to-many-jointable/">Redpill Linpro PHP Competence Group blog</a></p>
<img src="http://feeds.feedburner.com/~r/EatMyMonkeydust/~4/BrtsAc0JKvY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2010/11/277/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://eatmymonkeydust.com/2010/11/277/</feedburner:origLink></item>
		<item>
		<title>Redpill Linpro to host “State of Symfony 2″ conference hub in Oslo</title>
		<link>http://feedproxy.google.com/~r/EatMyMonkeydust/~3/Ns8Wf7hOGf4/</link>
		<comments>http://eatmymonkeydust.com/2010/06/redpill-linpro-to-host-symfony-2-conference-hub-in-oslo/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 08:55:41 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[conferences]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[hub]]></category>
		<category><![CDATA[oslo]]></category>
		<category><![CDATA[redpill linpro]]></category>
		<category><![CDATA[symfony 2]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=273</guid>
		<description><![CDATA[Conference hubs are a way for like minded people to get together and watch/discuss an online conference. One such hub will be hosted in Oslo, Norway by Redpill Linpro (the company I work for). Read Fabien&#8217;s blog bost about conference hubs here. We will be streaming the 10:00 conference on the 22nd June 2010. Refreshments [...]]]></description>
			<content:encoded><![CDATA[<p>Conference hubs are a way for like minded people to get together and watch/discuss an online conference. One such hub will be hosted in Oslo, Norway by <a href="http://www.redpill-linpro.com">Redpill Linpro</a> (the company I work for). <a href="http://www.symfony-project.org/blog/2010/06/09/state-of-symfony-2-conference-hubs" target="_blank">Read Fabien&#8217;s blog bost about conference hubs here</a>.</p>
<p>We will be streaming the 10:00 conference on the 22nd June 2010. Refreshments will be served, please give me a shout if you are interested in coming along so we can buy enough conference tickets (we may be less than 5 people otherwise) and arrange a good sized conference room.</p>
<p>Hope to see you there!</p>
<p>Russ.</p>
<img src="http://feeds.feedburner.com/~r/EatMyMonkeydust/~4/Ns8Wf7hOGf4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2010/06/redpill-linpro-to-host-symfony-2-conference-hub-in-oslo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://eatmymonkeydust.com/2010/06/redpill-linpro-to-host-symfony-2-conference-hub-in-oslo/</feedburner:origLink></item>
		<item>
		<title>Using Doctrine 2 with symfony 1.x [Part 1]</title>
		<link>http://feedproxy.google.com/~r/EatMyMonkeydust/~3/CutccMxWk_0/</link>
		<comments>http://eatmymonkeydust.com/2010/03/using-doctrine-2-with-symfony-1-x-part1/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 23:13:13 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Doctrine 2]]></category>
		<category><![CDATA[sfDoctrine2plugin]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=256</guid>
		<description><![CDATA[Background It&#8217;s been a while since Jonathan announced the availability of Doctrine 2 for Symfony 1.x (wouldn&#8217;t recommend trying it with anything less than 1.3) and a a few things have changed since then, so here&#8217;s a refresher. We are at a crossroads now with Symfony 2 looming on the horizon, and many developers may [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>It&#8217;s been a while since <a href="http://www.jwage.com/" target="_blank">Jonathan</a> announced the availability of <a href="http://www.symfony-project.org/blog/2009/10/05/symfony-and-doctrine-2" target="_blank">Doctrine 2 for Symfony 1.x</a> (wouldn&#8217;t recommend trying it with anything less than 1.3) and a a few things have changed since then, so here&#8217;s a refresher.</p>
<p>We are at a crossroads now with Symfony 2 looming on the horizon, and many developers may wish to wait until that is more stable (later this year) to make the move to Symfony 2 and Doctrine 2 simultaneously. This is not such a bad idea, however Doctrine 2 is already at a level where you may wish to consider using it in your projects, you won&#8217;t be disappointed if you do!</p>
<p>It will take me a while to explain why Doctrine 2 is better than Doctrine 1, and more importantly why you should start using &#8211; but you can just take my word for it and take a look at a couple of <a href="http://www.slideshare.net/search/slideshow?searchfrom=header&amp;q=doctrine+2" target="_blank">Jonathan&#8217;s presentations</a> to back up my claim. (I Recommend <a href="http://www.slideshare.net/jwage/doctrine-2-not-the-same-old-php-orm" target="_blank">Doctrine 2 &#8211; not the same old PHP ORM</a>)</p>
<h2>Getting started</h2>
<p>Check out the plugin and set up the database as described in <a href="http://www.symfony-project.org/blog/2009/10/05/symfony-and-doctrine-2">Jon&#8217;s blog</a>, but don&#8217;t configure the schema just yet <img src='http://eatmymonkeydust.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>We&#8217;re going to go all out with the &#8220;Doctrine 2&#8243; way of doing things, so we&#8217;ll be using annotations, not yaml or xml &#8211; although you can look up that syntax if you prefer. (A lot of the stuff below won&#8217;t work though &#8211; you can&#8217;t have multiple yaml files for example yet).</p>
<p>In your project configuration class, you will have access to some methods:</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> configureDoctrineConnection<span style="color: #009900;">&#40;</span>\Doctrine\ORM\Configuration <span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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> configureEntityManager<span style="color: #009900;">&#40;</span>\Doctrine\ORM\EntityManager <span style="color: #000088;">$em</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the first of these, you need to add all the things to configure Doctrine before the entity manager can be created. Once Doctrine has created the entity manager, you can use the second method if you need to, to further configure the entity manager. (Registering a Doctrine listener for example).</p>
<p>So, in your configureDoctrineConnection() method, you&#8217;ll want to do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Decide where you want the proxy classes to be stored, and which namespace they should use</span>
<span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setProxyDir</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sf_cache_dir&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/Proxies&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setProxyNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Proxies&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// You may want to make this environment specific for performance reasons</span>
<span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAutoGenerateProxyClasses</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSqlLogger</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// This will get things working, but later you will want to use APC</span>
<span style="color: #666666; font-style: italic;">// or another &quot;real&quot; cache for production</span>
<span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\Common\Cache\ArrayCache<span style="color: #339933;">;</span>
<span style="color: #000088;">$reader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\Common\Annotations\AnnotationReader<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMetadataCacheImpl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setQueryCacheImpl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Tell Doctrine where to find your entities (you may have more than one location)</span>
<span style="color: #666666; font-style: italic;">// This is mostly required for cli tasks that iterate over all of your entities</span>
<span style="color: #000088;">$paths</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sf_lib_dir&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/Entities&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Populate this with all the locations of your entities</span>
<span style="color: #000088;">$reader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDefaultAnnotationNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Doctrine\ORM\Mapping\\'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$annotation</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\ORM\Mapping\Driver\AnnotationDriver<span style="color: #009900;">&#40;</span><span style="color: #000088;">$reader</span><span style="color: #339933;">,</span> <span style="color: #000088;">$paths</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMetadataDriverImpl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$annotation</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Register all the classes that Doctrine needs to autoload</span>
<span style="color: #000088;">$classLoader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\Common\ClassLoader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Entities\doctrine'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIncludePath</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_lib_dir'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$classLoader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\Common\ClassLoader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Proxies&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIncludePath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachedir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$classLoader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\Common\ClassLoader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Another<span style="color: #000099; font-weight: bold;">\N</span>amespace&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIncludePath</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_lib_dir'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ok, that was a lot of stuff &#8211; but Doctrine 2 is more verbose &#8211; meaning less magic, but more explicit code. Some of the above calls may not be necessary &#8211; I need to do further testing, and also I&#8217;d like to get a lot of these things &#8220;standardised&#8221; in the plugin, so you can skip a lot of this if you follow a &#8220;default&#8221; path. The problem with the original release of the plugin was that it was not possible to have multiple class dirs, which makes it impossible to have plugins (for example) that also contain Entities. With the approach above, you explicitly add as many classes as you like to the annotation driver and the autoloader, and your plugin configuration classes can do the same.</p>
<h2>Active Entity</h2>
<p>The plugin comes bundled with Active Entity &#8211; this means that by extending ActiveEntity from our model classes (Entities) we can use our classes in much the same way as in Doctrine 1. Things like the following become available:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
\Entities\User<span style="color: #339933;">::</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>ActiveEntity was written and included with good intentions, because for Doctrine 2 to continue to be compatible with symony in the same way as Doctrine 1, a bit of magic needed to be re-introduced. <strong>BUT</strong> &#8211; for anyone that has been excited by Doctrine 2, one of the major breakthroughs is the non-intrusive model, and ActiveEntity kills that (along with a kitten):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//With ActiveEntity:</span>
<span style="color: #000000; font-weight: bold;">class</span> \Entities\User <span style="color: #000000; font-weight: bold;">extends</span>  \DoctrineExtensions\ActiveEntity <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Without ActiveEntity:</span>
<span style="color: #000000; font-weight: bold;">class</span> \Entities\User extends<span style="color: #339933;">-</span>or<span style="color: #339933;">-</span>does<span style="color: #339933;">-</span>not<span style="color: #339933;">-</span>extend  \Whatever\The\Hell\You\Like <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>So I strongly recommend that you <strong>Don&#8217;t</strong> extend ActiveEntity &#8211; and gradually the plugin will be &#8220;fixed&#8221; so that is never necessary. Currently basic object forms and some widgets are working fine without it, but I haven&#8217;t tested it with admin generators or anything like that yet so feedback is appreciated.</p>
<p>If you follow my advice, you have to do everything the &#8220;Doctrine 2 way&#8221;. That means taking control of your own code! Write your own getters and setters, extend your own classes (if you want to) &#8211; be verbose, write OOP code, etc!</p>
<h2>Ongoing development</h2>
<p>Doctrine 2 is still in Alpha at the moment and is constantly changing. Since we are using it actively in a project at the moment, we normally spot the changes pretty quickly and update the plugin to keep up, however we are not using all the aspects of the plugin (like generators, all the form widgets, etc) so from time to time something might completely fail when you svn up.</p>
<p>We are also trying to slowly, and safely (for BC) remove the need for ActiveEntity &#8211; but we&#8217;re being careful with this because we don&#8217;t want to break existing projects that are using it.</p>
<p>Report bugs in the usual way using the <a href="http://trac.symfony-project.org/newticket" target="_blank">symfony bug tracker</a> (if it&#8217;s plugin related) or on <a href="http://www.doctrine-project.org/jira/secure/CreateIssue!default.jspa" target="_blank">Doctrine Jira</a> (if you know it is a Doctrine issue). When reporting plugin bugs, please register the bug under the sfDoctrine component and <strong>add the keyword sfDoctrine2Plugin</strong> as I use a <a href="http://trac.symfony-project.org/query?status=new&amp;status=assigned&amp;status=reopened&amp;keywords=%7EsfDoctrine2Plugin&amp;order=priority" target="_blank">filtered query</a> to keep an eye on Doctrine 2 related issues.</p>
<h2>Coming in part 2&#8230;</h2>
<p>Will either be based on feedback/suggestions (if any) or I&#8217;ll move on to some real world examples and best practices when it comes to integrating symfony and Doctrine 2.</p>
<img src="http://feeds.feedburner.com/~r/EatMyMonkeydust/~4/CutccMxWk_0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2010/03/using-doctrine-2-with-symfony-1-x-part1/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://eatmymonkeydust.com/2010/03/using-doctrine-2-with-symfony-1-x-part1/</feedburner:origLink></item>
		<item>
		<title>Is symfony the best documented OS project out there?</title>
		<link>http://feedproxy.google.com/~r/EatMyMonkeydust/~3/aeanfMUNAz8/</link>
		<comments>http://eatmymonkeydust.com/2009/12/is-symfony-the-best-documented-os-project-out-there/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 14:19:08 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=241</guid>
		<description><![CDATA[Introduction Well, I&#8217;m not actually going to answer that question because there are many thousands of projects and I don&#8217;t actually know how well they are all documented, so it would be completely unfair of me! However, with the release of this year&#8217;s advent calendar symfony is at least setting a high standard for others [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Well, I&#8217;m not actually going to answer that question because there are many thousands of projects and I don&#8217;t actually know how well they are all documented, so it would be completely unfair of me! However, with the release of <a href="http://www.symfony-project.org/blog/2009/12/01/one-more-thing">this year&#8217;s advent calendar</a> symfony is at least setting a high standard for others to follow.</p>
<h2>So what should you read?</h2>
<p>In our office, we have several symfony books kicking around, and new developers often ask where to start. In fact, it can be quite frustrating to have to tell a new guy that the 2 days they&#8217;ve spent studying the &#8220;Definitive guide to symfony&#8221; has really only helped them to maintain our first project from 2 years ago&#8230;</p>
<h3>Starting a new project &amp; don&#8217;t know much about symfony</h3>
<ul>
<li><a href="http://www.symfony-project.org/jobeet/1_4/Doctrine/en/" target="_blank">Do the Jobeet tutorial</a> &#8211; seriously, no matter how much you think you can wing it, don&#8217;t. Set aside a couple of days and go through it. It&#8217;s even supported by an svn repository so you don&#8217;t have to type much code if you don&#8217;t want to &#8211; although be aware that the documentation is much more up to date that the code behind it, so if in doubt, trust the doc. The tutorial is also available<a href="http://www.symfony-project.org/jobeet/1_4/Propel/en/" target="_blank"> in the Propel flavour</a>.</li>
<li><a href="http://www.symfony-project.org/reference/1_4/en/" target="_blank">Scan the reference guide</a> - I&#8217;m not saying read it, unless you have bags of time, but at least give it a quick scan so you know what&#8217;s there. When you&#8217;re struggling later you&#8217;ll think &#8220;I&#8217;ve seen that somewhere&#8221; &#8211; and chances are it was in the reference guide</li>
</ul>
<h3>Know the basics and want to take it further</h3>
<ul>
<li><a href="http://www.symfony-project.org/forms/1_2/en/" target="_blank">Read the forms book </a>- The newer versions of symfony still support the forms framework and chances are you will want to use it, so it&#8217;s a good idea to give this a read. You will have a good idea already after doing the <a href="http://www.symfony-project.org/jobeet/1_4/Doctrine/en/" target="_blank"> Jobeet tutorial</a> but there are things you will have missed and this will open your eyes.</li>
<li>Read <a href="http://www.symfony-project.org/advent_calendar/" target="_blank">More with symfony</a> (the 2009 advent calendar) - If you&#8217;ve started to get the hang of things and want to know what &#8220;the experts&#8221; do when they are coding with symfony, this is where to look! This book has been written by members of the symfony community, so comes totally from the perspective of experienced developers who have been through the same process as the one you are going through.</li>
<li><a href="http://www.symfony-project.org/cookbook/1_2/en/" target="_blank">Browse the cookbook</a> &#8211; If there is something you are wondering about that seems like it would be a common task, there might well be a &#8220;recipe&#8221; for that very task! The cookbook has not made it to the 1.4 branch of documentation at the time of writing, but most of the recipes (if not all) will work just fine in the later versions. </li>
<li>Check <a href="http://trac.symfony-project.org/wiki/" target="_blank">the wiki</a> - this is basically a cookbook with user supplied recipies, whereas the &#8220;official&#8221; cookbook is maintained by the core team. That&#8217;s not to say it&#8217;s any less of a resource &#8211; just that it&#8217;s slightly more likely to contain &#8220;opinions&#8221; and out of date ideas.</li>
</ul>
<h3>Stuck with something</h3>
<ul>
<li>Check through all of the above &#8211; in particular the <a href="http://www.symfony-project.org/reference/1_4/en/" target="_blank">reference guide</a> and <a href="http://www.symfony-project.org/cookbook/1_2/en/" target="_blank">cookbook</a>. &#8220;Googling&#8221; for a well structured phrase will often get you to one of the correct pages in the manual &#8211; just be sure to switch it to the correct version, as a lot of the old 1.0 pages still come up first in searches.</li>
<li>Browse the <a href="http://www.symfony-project.org/api/1_4/" target="_blank">API documentation</a> - The symfony codebase is generally very well commented, so if you are wondering about the methods of a particular class, or the options for a widget, or some other property/function/value that you can&#8217;t find anywhere in the documentation, there is a good chance the api docs will help you out.</li>
</ul>
<h2>Getting &#8220;human&#8221; help</h2>
<p>Sometimes all the reading and googling gets you nowhere and you can quickly find yourself feeling very frustrated and alone. Fortunately symfony is backed by an enourmous community, and in a rare web-community-twist it&#8217;s one that works both ways. Not only do people ask questions, but there are hundreds of people around to answer them too!</p>
<h3>My personal &#8220;hangouts&#8221;</h3>
<ul>
<li>IRC &#8211; Need a quick answer, this is the place.  You won&#8217;t <em>always </em>get a quick answer, because there are a lot of lurkers, but there are also a lot of &#8220;regulars&#8221; who hang around in there so be patient and try again a bit later if you don&#8217;t get a response straight away. Check out freenode channel #symfony (I&#8217;m rooster).</li>
<li><a href="http://forum.symfony-project.org/index.php" target="_blank">Symfony forum</a> - Not quite as well publicised as the Google groups, but a valuable resource all the same. It&#8217;s really down to your communication preferences if you like forums or mailing lists, so just pick one (or both). What you will find is that different people are active on the forum compared to the Google group &#8211; it&#8217;s a shame there is not much harmony here as it can be a bit strange for newcomers. One thing I will say about the forum is that you will <em>always</em> get a response, if not by anyone else at least by Halfer, Ryan or myself (Russ).</li>
<li>Google <a href="http://groups.google.com/group/symfony-users" target="_blank">symfony users group</a> - Very busy but with a lot of experienced developers around to answer questions. Can take a bit longer than the forum to get a response, but you are generally speaking to a larger audience here. You are more likely to get a response from Fabien if you post here, he hasn&#8217;t posted in the forum for 6 months! I&#8217;m RussMonkey in this one.</li>
<li><a href="http://trac.symfony-project.org" target="_blank">Trac</a> - If you have to come to the conclusion that what you are working with is a bug, or maybe it took you way to long to find the answer because the documentation on the subject was wrong, missing or just bad, then please raise a ticket. Depending on the nature of the issue, it can seem like it takes a while to get a response &#8211; so rather than &#8220;bumping&#8221; comments in the ticket itself, it&#8217;s normally best to start a discussion in an appropriate place, most likely the <a href="http://groups.google.com/group/symfony-devs" target="_blank">dev mailing list</a> and be sure to link to the discussion from the ticket, and link to the ticket in the discussion.</li>
</ul>
<h2>Staying &#8220;fresh&#8221;</h2>
<p>It&#8217;s quite hard to keep up with everything that&#8217;s going on, so there are a few things that you really should do:</p>
<ul>
<li>Subsribe to the <a href="http://www.symfony-project.org/blog/" target="_blank">symfony project blog</a> - this is where you&#8217;ll get the most important news about changes and future development from the core team.</li>
<li>Subscribe to the <a href="http://trac.symfony-project.org/wiki/SymfonyBloggers" target="_blank">symfony bloggers</a> feed &#8211; blog posts from the community, including this one, appear here. It has grown quite substantially lately, and can get cluttered with non-English blogs, which really should be in a seperate feed to be honest &#8211; but if you are using a feed reader you can just skip over them (unless you can read that particular language of course). There are a lot of experienced bloggers here, and you&#8217;ll start to recognise some of the more useful ones as you read.</li>
<li>Subscribe to the <a href="http://groups.google.com/group/symfony-users" target="_blank">user group mailing list </a>- either as a daily digest, or an rss feed (my preference). It&#8217;s useful to scan through and see what people are talking about, so you can recognise recurring problems and issues that you may face one day.</li>
<li>Those above things should take no more than a few minutes a day to browse and keep an eye on, but if you really want to get a bit more involved and have a bit more time to spare, then consider IRC, the forum and the dev mailing list also. </li>
</ul>
<h2>Summary</h2>
<p>So, you can see why I am starting to believe that symfony is at least one of the best documented and supported projects out there, in this post alone I have listed 14 resources that the developer can use can make the most of their time developing. Symfony has a (somewhat improving) reputation for being a one man show when it comes to the direction of the project and the core coding, but that is certainly not the case when it comes to the community support side of things &#8211; you are not alone!</p>
<img src="http://feeds.feedburner.com/~r/EatMyMonkeydust/~4/aeanfMUNAz8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2009/12/is-symfony-the-best-documented-os-project-out-there/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://eatmymonkeydust.com/2009/12/is-symfony-the-best-documented-os-project-out-there/</feedburner:origLink></item>
		<item>
		<title>Random words and phrases – Pondus inspired</title>
		<link>http://feedproxy.google.com/~r/EatMyMonkeydust/~3/NfuVB5pbn_8/</link>
		<comments>http://eatmymonkeydust.com/2009/10/random-words-and-phrases-pondus-inspired/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 17:09:10 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[Learn Norwegian]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=233</guid>
		<description><![CDATA[I har ikke skrevet anything for a while, so whilst I read the new edition of Pondus I figured I might as well note a few nice ord and phrases I stumble across. I&#8217;ll also mention a few day-to-day things that I&#8217;ve come across that may be nyttig. Oh, and of course be a bit [...]]]></description>
			<content:encoded><![CDATA[<p>I <strong>har ikke skrevet</strong> anything for a while, so whilst I read the new edition of Pondus I figured I might as well note a few nice <strong>ord</strong> and phrases I stumble across. I&#8217;ll also mention a few day-to-day things that I&#8217;ve come across that may be <strong>nyttig</strong>. Oh, and of course be a bit<strong> forsiktig </strong>with the &#8220;<strong>Pondus ord</strong>&#8221; because many of them are of course quite &#8220;slangy&#8221;!</p>
<ul>
<li><strong>Det står ingenting på denne lappen</strong> &#8211; There is nothing on this ticket</li>
<li><strong>Overbevist</strong> &#8211; Satisfied</li>
<li><strong>Vellykket</strong> &#8211; Successful</li>
<li><strong>Du er nødt til å&#8230;</strong> &#8211; You really have to&#8230;</li>
<li><strong>Ta en blund &#8211; </strong>Take a nap</li>
<li><strong>Kan jeg få en sånn</strong> &#8211; May I have one of those/these? (Whilst pointing at something)</li>
<li><strong>Kjempeflaks</strong> &#8211; Really lucky</li>
<li><strong>Kollisjonsputer</strong> &#8211; Airbags</li>
<li><strong>Jeg må tidlig opp</strong> &#8211; I have to be up early</li>
<li><strong>Litt skuffa</strong> &#8211; A bit disappointed</li>
<li><strong>Vidunderlig</strong> &#8211; Wonderful</li>
<li><strong>Jeg er lei av&#8230;</strong> &#8211; I&#8217;m sick of&#8230;</li>
<li><strong>Jeg vil du skal&#8230;</strong> &#8211; I would like you to&#8230;</li>
<li><strong>Åpenbart</strong> &#8211; Obviously</li>
<li><strong>Ødelegge</strong> &#8211; Destroy</li>
<li><strong>Takk og lov!</strong> &#8211; Thank goodness!</li>
</ul>
<p>*vis words that I like:</p>
<ul>
<li><strong>Sannsynligvis &#8211; </strong>Probably<strong><br />
</strong></li>
<li><strong>Tilfeldigvis &#8211; </strong>Accidentally</li>
<li><strong>Forhåpentligvis</strong> &#8211; Hopefully</li>
<li><strong>Heldigvis &#8211; </strong>Luckily</li>
</ul>
<p>* P.s. When I write <strong>på engelsk</strong> I am borrowing a format that I really like, used by Kari in her <a href="http://www.transparent.com/norwegian/" target="_blank">Norwegian blog</a>. I urge you to subscribe to that one too!</p>
<img src="http://feeds.feedburner.com/~r/EatMyMonkeydust/~4/NfuVB5pbn_8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2009/10/random-words-and-phrases-pondus-inspired/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://eatmymonkeydust.com/2009/10/random-words-and-phrases-pondus-inspired/</feedburner:origLink></item>
		<item>
		<title>PHP Session settings ignored?</title>
		<link>http://feedproxy.google.com/~r/EatMyMonkeydust/~3/VN3XQZQqyIw/</link>
		<comments>http://eatmymonkeydust.com/2009/10/php-session-settings-ignored/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 16:43:37 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[configuration]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=229</guid>
		<description><![CDATA[I just read an extremely interesting post which explains an unwanted side effect of garbage collection by some Debian based systems. This cleanup process causes (maybe amongst other things) sessions to be cleared every 24 minutes, regardless of any ini setting you have set after the php.ini file is parsed (for example using ini_set() &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>I just read an <a href="http://elephpants.blog.linpro.no/2009/10/02/unwanted-end-of-sessions/">extremely interesting post</a> which explains an unwanted side effect of garbage collection by some Debian based systems. This cleanup process causes (maybe amongst other things) sessions to be cleared every 24 minutes, regardless of any ini setting you have set after the php.ini file is parsed (for example using ini_set() &#8211; if you are a symfony user, this is done during initialisation based on a setting in your factories.yml file).</p>
<p>Check it out: <a href="http://elephpants.blog.linpro.no/2009/10/02/unwanted-end-of-sessions/">http://elephpants.blog.linpro.no/2009/10/02/unwanted-end-of-sessions/</a></p>
<img src="http://feeds.feedburner.com/~r/EatMyMonkeydust/~4/VN3XQZQqyIw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2009/10/php-session-settings-ignored/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://eatmymonkeydust.com/2009/10/php-session-settings-ignored/</feedburner:origLink></item>
		<item>
		<title>Symfony forms – Flexible widgets based on user credentials (sfcontext is evil)</title>
		<link>http://feedproxy.google.com/~r/EatMyMonkeydust/~3/C_2S_4pK8O4/</link>
		<comments>http://eatmymonkeydust.com/2009/08/symfony-forms-flexible-widgets-based-on-user-credentials/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 13:42:09 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[forms]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=215</guid>
		<description><![CDATA[Background This issue has come up many times in the symfony forum and on IRC, and whilst it seems like a fairly trivial one, it is important to discuss the best practice around it. Often we want to modify a form based on something outside the form&#8217;s scope, like a user&#8217;s credentials or the page [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>This issue has come up many times in the symfony forum and on IRC, and whilst it seems like a fairly trivial one, it is important to discuss the best practice around it. Often we want to modify a form based on something outside the form&#8217;s scope, like a user&#8217;s credentials or the page they are on, or maybe some session values &#8211; lets take the example of a dropdown widget where admin users get to see a few more options.</p>
<h2>The bad way</h2>
<p>Everyone that has been using symfony for a while is aware of the context singleton. This magic sprite allows us to grab all sorts of information about the context we are in, including the user, session, request, view, and many more things. Whilst it certainly has its place, most of the time, however, we should avoid using it. The clue to the reason why is carefully disguised in the class name &#8220;Context&#8221;.</p>
<p>When we refer to a context in our code, we are locking ourselves in to the fact that the context must exist, so every time we use it we are basically saying that this class can now only be used in a symfony project with a fully initialised symfony stack hanging over it.  This becomes a problem in things like unit tests, where you have to mock up a loaded context object with bells and whistles in order to test a simple function or class.</p>
<p>So this is what you might think of doing:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// In your form class</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$choices</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;something boring&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;something dull&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$currentUser</span> <span style="color: #339933;">=</span> sfContext<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;">getUser</span><span style="color: #009900;">&#40;</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;">$currentUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isAuthenticated</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$currentUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasCredential</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;admin&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$choices</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;something cool&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;something leet&quot;</span><span style="color: #009900;">&#41;</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>The reason this is bad is that the forms framework is a standalone framework &#8211; it should be possible to pick up your form class and drop it into any project. It should also be possible to test it independently of symfony, without being tied in by sfContext. So what is the better way?</p>
<h2>The dependency injection approach</h2>
<p>You might read that and think &#8220;woah, this is getting complicated!&#8221; but we&#8217;re not talking about dependency injection containers here, we&#8217;re simply saying that you can make your form object depend on something to run. The thing it depends on should not be the context singleton, it should be the minimum thing that the form needs to operate correctly &#8211; which in this case, is a user object that supports credentials.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// In your actions.class.php</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> myForm<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentUser&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// In your form class</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentUser&quot;</span><span style="color: #009900;">&#41;</span> instanceof sfUser<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> InvalidArgumentException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;You must pass a user object as an option to this form!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The test here is where we are making this form &#8220;dependent&#8221; on a user object. In this case we are insisting that the object is an instance of sfUser, which you may argue is tying us in to symfony again, but you could use any test here to ensure that the object will have the necessary functionality you need, maybe check for the existence of a &#8220;hasCredential()&#8221; method for example.</p>
<p>When writing a test for this form class, we now only need to instantiate a user object and load it with some credentials &#8211; much easier than doing the same thing and locking into a context singleton. There may be other times when this form could be useful in a lightweight environment, where you can get speedy access to a user object but don&#8217;t want the overhead of the symfony context &#8211; you might not think of one now, but it&#8217;s best to code this way and you&#8217;ll have less reasons to kick yourself further down the line.</p>
<h2>The completed code, for our single widget form</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// In your form class</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</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: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentUser&quot;</span><span style="color: #009900;">&#41;</span> instanceof sfUser<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> InvalidArgumentException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;You must pass a user object as an option to this form!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$currentUser</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$choices</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;something boring&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;something dull&quot;</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;">$currentUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isAuthenticated</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$currentUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasCredential</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;admin&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$choices</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;something cool&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;something leet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_dropdown'</span><span style="color: #009900;">&#93;</span>    <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;choices&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$choices</span><span style="color: #009900;">&#41;</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;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_dropdown'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;choices&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$choices</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Wrap up</h2>
<p>Think about this example the next time you think about modifying a query based on a user object, or session value in a peer class, or Doctrine table class&#8230; Maybe you should have passed a parameter there too? Every class and method you write, think about how you can reuse it, will it even be possible the way you have written it? If something simply <strong>must</strong> be coded in a symfony specific way, think about making a parent and a child class for the problem you are trying to solve. In the parent class, you can make things as generic as possible &#8211; so you can re-use that class to your heart&#8217;s content. In the child class, you can add the symfony specific code &#8211; kept to a minimum.</p>
<img src="http://feeds.feedburner.com/~r/EatMyMonkeydust/~4/C_2S_4pK8O4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2009/08/symfony-forms-flexible-widgets-based-on-user-credentials/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		<feedburner:origLink>http://eatmymonkeydust.com/2009/08/symfony-forms-flexible-widgets-based-on-user-credentials/</feedburner:origLink></item>
		<item>
		<title>Chris Ryan inspired Norwegian vocabulary – Blodpenger chapter 1</title>
		<link>http://feedproxy.google.com/~r/EatMyMonkeydust/~3/HKYZy4NZOFU/</link>
		<comments>http://eatmymonkeydust.com/2009/06/random-chris-ryan-inspired-norwegian-vocabulary-bloodpenger-chapter1/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 21:22:35 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[Learn Norwegian]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=213</guid>
		<description><![CDATA[Why? I haven&#8217;t been too active lately with the Norwegian blog, mostly because of the usal lame excuse regarding time and too much work and all that. One thing I have been doing lately is reading, or at least trying to read the Chris Ryan book &#8220;Blodpenger&#8221;, and during this reading several words crop up [...]]]></description>
			<content:encoded><![CDATA[<h1>Why?</h1>
<p>I haven&#8217;t been too active lately with the Norwegian blog, mostly because of the usal lame excuse regarding time and too much work and all that. One thing I have been doing lately is reading, or at least trying to read the Chris Ryan book &#8220;Blodpenger&#8221;, and during this reading several words crop up that are interesting &#8211; but which I forget way too quickly.</p>
<p>Hopefully by sharing some of them here, it will help me to remember, and also give me a quick reference point for when I inevitably forget again!</p>
<h1>Some words &#8211; from prologue and chapter 1</h1>
<ul>
<li>Sylige &#8211; visible</li>
<li>Stram &#8211; tight (fingrene var stram)</li>
<li>Forvridd &#8211; contorted, mangled, twisted (På ringfingeren satt en forvridd gullring)</li>
<li>Dugg &#8211; dew</li>
<li>Grundigere &#8211; thoughtfully</li>
<li>Bøye &#8211; bend (han bøyde seg = he bent over)</li>
<li>Tilhøre &#8211; belong to (måtte ha tilørt en kvinne)</li>
<li>Halvannen &#8211; one and a half</li>
<li>en Grop ( a ditch)</li>
<li>Peste &#8211; panted (den peste mens den løp)</li>
<li>Ryggsøyle &#8211; spine</li>
<li>Mistanke &#8211; suspicion</li>
<li>Nøyaktig &#8211; precisely</li>
<li>Gjørmete &#8211; muddy</li>
<li>Gned &#8211; rubbed</li>
<li>Slør &#8211; veil</li>
<li>Blikk &#8211; look, glance (hun løftet blikket)</li>
<li>Lynraskt &#8211; very quickly, blazingly, &#8220;at light speed&#8221;</li>
<li>Påføre &#8211; cause, bring upon</li>
<li>Som ventet &#8211; as expected (den var som ventet)</li>
<li>Ifølge &#8211; according to</li>
<li>Somle &#8211; faff, dawdle, time waste</li>
<li>Myke halsen &#8211; stiff neck</li>
<li>Klesplagg &#8211; Garment, Item of clothing (et nytt klesplagg)</li>
<li>Øreflippen &#8211; the earlobe</li>
<li>Slikket &#8211; licked</li>
<li>Åndsfraværende &#8211; vacantly (Han slikket øreflippen hennes åndsfraværende)</li>
<li>Ånd &#8211; spirit, Fraværende &#8211; absent</li>
<li>Bekymret &#8211; worried, concerned (det som bekymret ham)</li>
<li>Fortjener &#8211; deserve</li>
<li>Halvt fordervet &#8211; half to death (han slo henne halv fordervet)</li>
<li>Tillatelse &#8211; permission</li>
</ul>
<p>And that&#8217;s not even the whole chapter&#8230;</p>
<img src="http://feeds.feedburner.com/~r/EatMyMonkeydust/~4/HKYZy4NZOFU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2009/06/random-chris-ryan-inspired-norwegian-vocabulary-bloodpenger-chapter1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://eatmymonkeydust.com/2009/06/random-chris-ryan-inspired-norwegian-vocabulary-bloodpenger-chapter1/</feedburner:origLink></item>
	</channel>
</rss>
