<?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>Not My Idea</title>
	<atom:link href="http://www.notmyidea.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.notmyidea.org</link>
	<description>Developpement et Architecture logicielle, par Alexis Métaireau</description>
	<lastBuildDate>Tue, 23 Jun 2009 09:10:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dependency Injection &#8211; Using SpiralDi Container</title>
		<link>http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/</link>
		<comments>http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 09:10:26 +0000</pubDate>
		<dc:creator>Alexis Metaireau</dc:creator>
				<category><![CDATA[Architecture logicielle]]></category>
		<category><![CDATA[php-en]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[spiral]]></category>

		<guid isPermaLink="false">http://www.notmyidea.org/?p=226</guid>
		<description><![CDATA[Please note that this article is also available in French. A big thanks to Frédéric Sureau for his translation work on the English version.
Since my previous article (FR), I have kept on working on the dependencies injector of Spiral, wich I just published in a standalone version.
Here is an overview of SpiralDi functionnalities, and some [...]]]></description>
			<content:encoded><![CDATA[<p class="info">Please note that this article is also <a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php">available in French</a>. A big thanks to Frédéric Sureau for his translation work on the English version.</p>
<p>Since my <a href="http://www.notmyidea.org/article/dependency-injection-singleton-design-pattern-ioc-dendencies-dependences/">previous article (FR)</a>, I have kept on working on the dependencies injector of <a href="http://bitbucket.org/ametaireau/spiral/wiki/Home">Spiral</a>, wich I just published in a <a href="http://bitbucket.org/ametaireau/spiraldi/"><em>standalone</em> version</a>.</p>
<p>Here is an overview of SpiralDi functionnalities, and some examples on the use.<br />
<span id="more-226"></span></p>
<h2>Table des matières</h2>
<div class="toc">
<ol>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-overview">Overview</a></li>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-principles">Principles</a>
<ol>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-services-scope">Services scope</a></li>
</ol>
</li>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-advanced-use">Advanced use</a>
<ol>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-using-references-and-methodfactory">Using references and <em>MethodFactory</em></a></li>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-inheriting-and-overloading-services">Inheriting and overloading services</a></li>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-container-aware">Container Aware</a></li>
</ol>
</li>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-factories">Factories</a></li>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-download-it">Download it ! </a>
<ol>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-via-the-mercurial-repository">Via the mercurial repository</a></li>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-via-the-archives">Via the archives</a></li>
</ol>
</li>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-interesting-readings">Interesting readings</a></li>
<li><a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/#toc-going-further">Going further ?</a></li>
</ol>
</div>
<h2 id="toc-overview">Overview</h2>
<p>SpiralDi comes with a lot of new features, some of them inspired by the excellent Java framework : Spring. It is now possible to :</p>
<ul>
<li>Use <em>factories</em> to set the parameters values (useful for configuration)</li>
<li>Use an inheritance system to make configuration file more clear</li>
<li>Use <em>factories</em> for the construction of the services</li>
<li>Directly inject the container in <em>ContainerAware</em> services</li>
</ul>
<p>But, maybe, it doesn&#8217;t mean anything for you ? I will explain the details further later.</p>
<h2 id="toc-principles">Principles</h2>
<p>If you don&#8217;t know much about the inversion of control, I advise you to read my <a href="http://www.notmyidea.org/article/dependency-injection-singleton-design-pattern-ioc-dendencies-dependences/">introduction on the dependencies injection (FR)</a>.</p>
<p>The use of a lightweight container is done in two steps :</p>
<ul>
<li>The description of the <em>schema</em> of all the services that will be used later</li>
<li>The call (so, the construction) of these services via the <em>container</em></li>
</ul>
<p>The SpiralDi library let you describe the <em>Schema</em> in different ways. The sexiest is probably the XML description file, but it is also possible to define this <em>Schema</em> using the PHP language if you think it&#8217;s more convenient. The following examples are in XML. Here is a quite simple definition file, that describe two services :</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3">&lt; ?xml <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;container<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;db&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Database&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;constructor<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">value</span>=<span class="st0">&quot;localhost&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">value</span>=<span class="st0">&quot;root&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">value</span>=<span class="st0">&quot;password&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/constructor<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;user&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;User&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;setDb&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">type</span>=<span class="st0">&quot;service&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;db&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/method<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/container<span class="re2">&gt;</span></span></span></div></div>
<p>Once this file is written, you have to transform it in a SpiralDi understandable format : the Schema.</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="re0">$builder</span> <span class="sy0">=</span> <span class="kw2">new</span> SpiralDi_SchemaBuilder_Xml<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$builder</span><span class="sy0">-&gt;</span><span class="me1">setFileName</span><span class="br0">&#40;</span><span class="st0">&quot;schema.xml&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$schema</span> <span class="sy0">=</span> <span class="re0">$builder</span><span class="sy0">-&gt;</span><span class="me1">buildSchema</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<p>You can now exploit the built Schema. The Schema is first used to resolve objects. We will see later that it has much more aims. Now, pass this <em>Schema</em> to the <em>Container</em> :</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">// construction of the container</span><br />
<span class="re0">$container</span> <span class="sy0">=</span> <span class="kw2">new</span> SpiralDi_Container_Default<span class="br0">&#40;</span><span class="re0">$schema</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
<span class="co1">// getting the desired service</span><br />
<span class="re0">$myUser</span> <span class="sy0">=</span> <span class="re0">$container</span><span class="sy0">-&gt;</span><span class="me1">user</span><span class="sy0">;</span></div></div>
<p>This looks sexy, isn&#8217;t it ? The container has done everything ! Resolution of the object&#8217;s dependencies and injection of these dependencies when needed.</p>
<h3 id="toc-services-scope">Services scope</h3>
<p>All services constructed by SpiralDi have a controlled life time.<br />
In the default behavior, the container will return the same instance of the object, each time the service is needed. This is the <em>singleton</em> scope.<br />
All services are by default configured to have the <em>singleton</em> scope.</p>
<p>You can also use the <em>prototype</em> scope to make the container create a new instance each time the service is needed.</p>
<p>To change the scope of the service, you can use the property</p>
<div class="codecolorer-container text notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">scope=&quot;prototype&quot;</div></div>
<p>in the XML file.</p>
<h2 id="toc-advanced-use">Advanced use</h2>
<p>Now, you know how to describe &laquo;&nbsp;basic&raquo;&nbsp; services and their dependencies. Let&#8217;s see now, more complex features.</p>
<h3 id="toc-using-references-and-methodfactory">Using references and <em>MethodFactory</em></h3>
<p>Sometimes, you will need to inject parameters in a dynamic manner. Imagine that you don&#8217;t know the value of a parameter that you want to inject because it is stored in a configuration object for example.</p>
<p>So, we want the container to construct our services using information from a <em>Config</em> object. The container is able to generate automatically the following code for us :</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="re0">$config</span> <span class="sy0">=</span> <span class="kw2">new</span> Config<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$service</span> <span class="sy0">=</span> <span class="kw2">new</span> Db<span class="br0">&#40;</span><span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">host</span><span class="sy0">,</span> <span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">user</span><span class="sy0">,</span> <span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">password</span><span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<p>For this, we have to use the system of references :</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;db&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Database&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;constructor<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">ref</span>=<span class="st0">&quot;config&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;host&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">ref</span>=<span class="st0">&quot;config&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;user&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">ref</span>=<span class="st0">&quot;config&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;password&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/constructor<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div></div>
<p>It is also possible to specify the method that will be used to get arguments. For example</p>
<div class="codecolorer-container text notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">getParam()</div></div>
<p>will produce something like this :</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="re0">$config</span> <span class="sy0">=</span> <span class="kw2">new</span> Config<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$service</span> <span class="sy0">=</span> <span class="kw2">new</span> Db<span class="br0">&#40;</span><br />
&nbsp; &nbsp; <span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">getParam</span><span class="br0">&#40;</span><span class="st0">&quot;host&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span> <br />
&nbsp; &nbsp; <span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">getParam</span><span class="br0">&#40;</span><span class="st0">&quot;user&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span> <br />
&nbsp; &nbsp; <span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">getParam</span><span class="br0">&#40;</span><span class="st0">&quot;password&quot;</span><span class="br0">&#41;</span><br />
<span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<p>The corresponding XML code will be :</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">ref</span>=<span class="st0">&quot;config&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;host&quot;</span> <span class="re0">factoryMethod</span>=<span class="st0">&quot;getParam&quot;</span><span class="re2">/&gt;</span></span></div></div>
<h3 id="toc-inheriting-and-overloading-services">Inheriting and overloading services</h3>
<p>Quite often, some services are similar. It is possible to use the inheritance system to make the services description lighter.<br />
This is not an actual inheritance between classes, but only the inheritance principle. Thus, you can extend a service description, which make the description file more readable and easier to understand.</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;extendedService&quot;</span> <span class="re0">extends</span>=<span class="st0">&quot;config&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;method2&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">value</span>=<span class="st0">&quot;value&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/method<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div></div>
<h3 id="toc-container-aware">Container Aware</h3>
<p>In some cases, services have to know the existence of the container, and need to access to it. It is easy to inject the container in a service by using the &laquo;&nbsp;container&raquo;&nbsp; type or the facility &laquo;&nbsp;containerAware&raquo;&nbsp; :</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;containerAwareService&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Service&quot;</span> <span class="re0">containerAware</span>=<span class="st0">&quot;true&quot;</span><span class="re2">/&gt;</span></span><br />
<span class="sc-1">&lt;!-- is exactly the same as --&gt;</span><br />
<span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;containerAwareService&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Service&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;setDiContainer&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">type</span>=<span class="st0">&quot;container&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/method<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div></div>
<p>From the class&#8217; point of view, you only have to implement the <em>SpiralDi_ContainerAware</em> interface. In this way, during the construction of the service, the <em>setDiContainer</em> method of your class will be automatically called.</p>
<p>As well, in this case, there is no need to explicitly name your service as &laquo;&nbsp;ContainerAware&raquo;&nbsp; in the description file, the container will automatically detect it</p>
<h2 id="toc-factories">Factories</h2>
<p>SpiralDi also provides a convenient way to use Factories from the DI. This helps generating behaviors like :</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="re0">$service</span> <span class="sy0">=</span> MyServiceFactory<span class="sy0">::</span><span class="me2">createService</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<p>The corresponding XML code is :</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;serviceFactory&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;factory&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;MyServiceFactory&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;createService&quot;</span> <span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div></div>
<p>This should be nice if you want to reuse your old Singleton implementations, among other things&#8230;</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;singleton&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;factory&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Mysingleton&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;getInstance&quot;</span> <span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div></div>
<h2 id="toc-download-it">Download it ! </h2>
<p>Convinced ? To get the latest version of SpiralDi, you have many solutions :</p>
<h3 id="toc-via-the-mercurial-repository">Via the mercurial repository</h3>
<div class="codecolorer-container bash notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">hg clone https:<span class="sy0">//</span>ametaireau<span class="sy0">@</span>bitbucket.org<span class="sy0">/</span>ametaireau<span class="sy0">/</span>spiraldi<span class="sy0">/</span></div></div>
<h3 id="toc-via-the-archives">Via the archives</h3>
<p>The code is available in the following formats : <a href="http://bitbucket.org/ametaireau/spiraldi/get/tip.zip">zip</a>, <a href="http://bitbucket.org/ametaireau/spiraldi/get/tip.gz">gz</a> ou <a href="http://bitbucket.org/ametaireau/spiraldi/get/tip.bz2">bz2</a></p>
<p>You can also <a href="http://bitbucket.org/ametaireau/spiraldi/">directly check the repository</a>.</p>
<p>That&#8217;s all ! You can now have fun using it ! For functionnality requests, bug report, etc. <a href="http://bitbucket.org/ametaireau/spiraldi/issues/new/">Please</a> !</p>
<h2 id="toc-interesting-readings">Interesting readings</h2>
<p>If you want to know more about dependencies injection, here are some interesting readings on the subject :</p>
<ul>
<li><a href="http://www.martinfowler.com/articles/injection.html">Martin Fowler&#8217;s article on dependencies injection</a></li>
<li>Fabien potencier&#8217;s suite of articles (<a href="http://fabien.potencier.org/article/11/what-is-dependency-injection">1</a>,<a href="http://fabien.potencier.org/article/12/do-you-need-a-dependency-injection-container">2</a>,<a href="http://fabien.potencier.org/article/13/introduction-to-the-symfony-service-container">3</a>,<a href="http://fabien.potencier.org/article/14/symfony-service-container-using-a-builder-to-create-services">4</a>,<a href="http://github.com/fabpot/Pimple/tree/master">5</a>)</li>
<li>Another one from Padraic Brady (<a href="http://blog.astrumfutura.com/archives/394-The-Case-For-Dependency-Injection-Part-1.html">1</a>,<a href="http://blog.astrumfutura.com/archives/395-The-Case-For-Dependency-Injection-Part-2.html">2</a>) </li>
<li>Fabien Potencier has also published a di container <a href="http://twittee.org/">that feet in a tweet</a>. to see, just for fun <img src='http://www.notmyidea.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<h2 id="toc-going-further">Going further ?</h2>
<p>SpiralDi is of course not the only PHP lightweight container. Recently, a lot of container are flowering on the web. Frameworks like Symfony and Flow3<sup>1</sup> are giving a good place to DI. So much the better !</p>
<ul>
<li><a href="http://svn.symfony-project.com/components/dependency_injection/">Symfony&#8217;s services container</a></li>
<li><a href="http://github.com/beberlei/yadif/tree/master">Yadim</a></li>
<li><a href="http://flow3.typo3.org/documentation/reference/object/">Flow3 Objects</a></li>
<li><a href="http://www.beberlei.de/sphicy/">Sphicy</a></li>
<li><a href="http://www.sourceforge.net/projects/phemto">Phemto</a></li>
<li><a href="http://www.seasar.org/en/php5/DIContainer.html">Seasar</a></li>
<li><a href="http://garden.tigris.org/">Garden</a></li>
<li><a href="http://en.wikipedia.org/wiki/Xyster_Framework">Xyster</a></li>
<li><a href="http://www.lionframework.org/">Lion</a></li>
</ul>
<ol class="footnotes"><li id="footnote_0_226" class="footnote">It is new, beautiful, written for PHP 5.3, using AOP, <em>Domain Model</em> persistence&#8230; and of course dependencies injection ! Keep an eye on it : <a href="http://flow3.typo3.org/">Flow3 </a></li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Injection de dépendances &#8211; Utilisation du SpiralDi Container</title>
		<link>http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/</link>
		<comments>http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 09:05:38 +0000</pubDate>
		<dc:creator>Alexis Metaireau</dc:creator>
				<category><![CDATA[Architecture logicielle]]></category>
		<category><![CDATA[php-fr]]></category>
		<category><![CDATA[Injection de dépendances]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[spiral]]></category>

		<guid isPermaLink="false">http://www.notmyidea.org/?p=189</guid>
		<description><![CDATA[Cet article est également disponible en version anglaise. Un grand merci à Frédéric Sureau pour son travail de traduction.
Suite à mon précédent article, j&#8217;ai continué à travailler sur l&#8217;injecteur de dépendances de Spiral, que je viens de publier dans une version standalone. 
Voici un tour d&#8217;horizon des fonctionnalités apportées par SpiralDi, ainsi que quelques exemples [...]]]></description>
			<content:encoded><![CDATA[<p class="info">Cet article est également <a href="http://www.notmyidea.org/article/en-introduction-to-spiral-dependency-injection-container-in-php">disponible en version anglaise</a>. Un grand merci à Frédéric Sureau pour son travail de traduction.</p>
<p>Suite à mon <a href="http://www.notmyidea.org/article/dependency-injection-singleton-design-pattern-ioc-dendencies-dependences/">précédent article</a>, j&#8217;ai continué à travailler sur l&#8217;injecteur de dépendances de <a href="http://bitbucket.org/ametaireau/spiral/wiki/Home">Spiral</a>, que je viens de publier dans une <a href="http://bitbucket.org/ametaireau/spiraldi/">version <em>standalone</em></a>. </p>
<p>Voici un tour d&#8217;horizon des fonctionnalités apportées par SpiralDi, ainsi que quelques exemples d&#8217;utilisation.<br />
<span id="more-189"></span></p>
<h2>Table des matières</h2>
<div class="toc">
<ol>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-tour-dhorizon">Tour d&#8217;horizon</a></li>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-principes">Principes</a>
<ol>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-portee-des-services-scopes">Portée des services (Scopes)</a></li>
</ol>
</li>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-utilisation-avancee">Utilisation &laquo;&nbsp;avancée&raquo;&nbsp;</a>
<ol>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-utilisation-des-references-et-des-methodfactory">Utilisation des Références et des <em>MethodFactory</em></a></li>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-heritage-et-surcharge-de-services">Héritage et surcharge de services</a></li>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-container-aware">Container Aware</a></li>
</ol>
</li>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-factories">Factories</a></li>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-telechargez-le">Téléchargez le ! </a>
<ol>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-via-le-depot-mercurial">Via le dépôt mercurial</a></li>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-via-les-archives">Via les archives</a></li>
</ol>
</li>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-et-ailleurs">Et ailleurs ?</a></li>
<li><a href="http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/#toc-lectures-interessantes">Lectures intéressantes</a></li>
</ol>
</div>
<h2 id="toc-tour-dhorizon">Tour d&#8217;horizon</h2>
<p>SpiralDi arrive avec son lot de nouveautés, pour certaines inspirées de l&#8217;excellent framework Java Spring. Il est désormais possible, en vrac, de:</p>
<ul>
<li>Utiliser des <em>factories</em> pour renseigner les valeurs des parametres (pratique pour la configuration)</li>
<li>Utiliser un système d&#8217;héritage, pour alléger les fichiers de configuration</li>
<li>Utiliser des <em>Factories</em> pour résoudre les services</li>
<li>Injecter directement le conteneur à certains services, dits <em>ContainerAware</em></li>
</ul>
<p>Mais peut être que ça ne vous parles pas trop, nous y reviendrons tout à l&#8217;heure.</p>
<h2 id="toc-principes">Principes</h2>
<p>Si vous n&#8217;êtes pas à l&#8217;aise avec le principe d&#8217;inversion de contrôle, je vous conseille d&#8217;aller lire mon <a href="http://www.notmyidea.org/article/dependency-injection-singleton-design-pattern-ioc-dendencies-dependences/">introduction sur l&#8217;injection de dépendances</a>.</p>
<p>L&#8217;utilisation d&#8217;un conteneur léger se fait toujours en deux étapes:</p>
<ul>
<li>La description et le renseignement du <em>schéma</em> de services qui pourront être utilisés par la suite</li>
<li>la demande de résolution de ces derniers, via le <em>conteneur</em></li>
</ul>
<p>SpiralDi fournit plusieurs manières de décrire le <em>Schema</em>. La plus appropriée est surement l&#8217;XML, mais il est également possible de passer via du PHP si cela vous semble plus pratique. Nous prendrons ici l&#8217;exemple du XML. Voici un fichier de description assez simple, qui décrit deux services:</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3">&lt; ?xml <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;container<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;db&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Database&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;constructor<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">value</span>=<span class="st0">&quot;localhost&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">value</span>=<span class="st0">&quot;root&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">value</span>=<span class="st0">&quot;password&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/constructor<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;user&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;User&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;setDb&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">type</span>=<span class="st0">&quot;service&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;db&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/method<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/container<span class="re2">&gt;</span></span></span></div></div>
<p>Une fois le fichier écrit, il faut le transformer dans un format compréhensible par SpiralDi: le Schema.</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="re0">$builder</span> <span class="sy0">=</span> <span class="kw2">new</span> SpiralDi_SchemaBuilder_Xml<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$builder</span><span class="sy0">-&gt;</span><span class="me1">setFileName</span><span class="br0">&#40;</span><span class="st0">&quot;schema.xml&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$schema</span> <span class="sy0">=</span> <span class="re0">$builder</span><span class="sy0">-&gt;</span><span class="me1">buildSchema</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<p>Nous pouvons désormais exploiter notre Schema. La première utilité d&#8217;un Schéma est d&#8217;être utilisé pour résoudre nos objets. Nous verrons un peu plus tard qu&#8217;il peut avoir d&#8217;autres utilités. Passons donc le <em>Schema</em> au <em>Conteneur</em>:</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">// construction du conteneur</span><br />
<span class="re0">$container</span> <span class="sy0">=</span> <span class="kw2">new</span> SpiralDi_Container_Default<span class="br0">&#40;</span><span class="re0">$schema</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
<span class="co1">// récupération du service souhaité</span><br />
<span class="re0">$myUser</span> <span class="sy0">=</span> <span class="re0">$container</span><span class="sy0">-&gt;</span><span class="me1">user</span><span class="sy0">;</span></div></div>
<p>Plutôt sympa non? Le conteneur s&#8217;est occupé de tout: résolution des dépendances de l&#8217;objet, et injection de ces dernières quand nécessaire.</p>
<h3 id="toc-portee-des-services-scopes">Portée des services (Scopes)</h3>
<p>Les services construits via SpiralDi ont une durée de vie contrôlée.<br />
Par défaut, plusieurs demandes au conteneur pour un même service retournerons la même instance de l&#8217;objet, il s&#8217;agit de la portée de type <em>singleton</em>.<br />
Le conteneur est configuré par défaut pour que les services qu&#8217;ils crée aient une portée de type <em>singleton</em>.</p>
<p>Il est possible d&#8217;utiliser la portée <em>prototype</em> pour qu&#8217;un nouvel objet soit créé à chaque appel du service, en utilisant la propriété</p>
<div class="codecolorer-container text notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">scope=&quot;prototype&quot;</div></div>
<p>dans le fichier XML.</p>
<h2 id="toc-utilisation-avancee">Utilisation &laquo;&nbsp;avancée&raquo;&nbsp;</h2>
<p>Vous savez désormais comment décrire &laquo;&nbsp;basiquement&raquo;&nbsp; vos services et leurs dépendances. Voyons maintenant quelques concepts un peu plus poussés.</p>
<h3 id="toc-utilisation-des-references-et-des-methodfactory">Utilisation des Références et des <em>MethodFactory</em></h3>
<p>Il peut arriver que l&#8217;on ai besoin d&#8217;injecter des paramètres de manière dynamique. Imaginez que vous ne connaissiez pas la valeur des paramètres à injecter, ceux-ci étant contenus dans un objet de configuration par exemple.</p>
<p>Nous souhaitons donc que le conteneur construise nos objets en utilisant des informations contenues dans la configuration. Le conteneur est donc capable de s&#8217;occuper de générer le code suivant à notre place:</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="re0">$config</span> <span class="sy0">=</span> <span class="kw2">new</span> Config<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$service</span> <span class="sy0">=</span> <span class="kw2">new</span> Db<span class="br0">&#40;</span><span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">host</span><span class="sy0">,</span> <span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">user</span><span class="sy0">,</span> <span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">password</span><span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<p>Pour cela, il faut utiliser le système de réferences:</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;db&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Database&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;constructor<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">ref</span>=<span class="st0">&quot;config&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;host&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">ref</span>=<span class="st0">&quot;config&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;user&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">ref</span>=<span class="st0">&quot;config&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;password&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/constructor<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div></div>
<p>Il est également possible de spécifier la méthode à utiliser pour résoudre les arguments,</p>
<div class="codecolorer-container text notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">getParam()</div></div>
<p>par exemple, pour arriver à quelque chose de ce genre:</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="re0">$config</span> <span class="sy0">=</span> <span class="kw2">new</span> Config<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$service</span> <span class="sy0">=</span> <span class="kw2">new</span> Db<span class="br0">&#40;</span><br />
&nbsp; &nbsp; <span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">getParam</span><span class="br0">&#40;</span><span class="st0">&quot;host&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span> <br />
&nbsp; &nbsp; <span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">getParam</span><span class="br0">&#40;</span><span class="st0">&quot;user&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span> <br />
&nbsp; &nbsp; <span class="re0">$config</span><span class="sy0">-&gt;</span><span class="me1">getParam</span><span class="br0">&#40;</span><span class="st0">&quot;password&quot;</span><span class="br0">&#41;</span><br />
<span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<p>Le code XML est alors le suivant:</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">ref</span>=<span class="st0">&quot;config&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;host&quot;</span> <span class="re0">factoryMethod</span>=<span class="st0">&quot;getParam&quot;</span><span class="re2">/&gt;</span></span></div></div>
<h3 id="toc-heritage-et-surcharge-de-services">Héritage et surcharge de services</h3>
<p>Assez souvent, certains services à injecter se ressemblent. Il est possible d&#8217;utiliser un système d&#8217;héritage pour rendre la description des services moins rébarbative. Il ne s&#8217;agit pas d&#8217;un héritage &laquo;&nbsp;concret&raquo;&nbsp; dans nos classes, mais du principe de l&#8217;héritage. Ainsi, une description peut en étendre une autre, facilitant à la fois son écriture et sa compréhension.</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;extendedService&quot;</span> <span class="re0">extends</span>=<span class="st0">&quot;config&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;method2&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">value</span>=<span class="st0">&quot;value&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/method<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div></div>
<h3 id="toc-container-aware">Container Aware</h3>
<p>Dans certains cas, il peut être utile qu&#8217;un service soit conscient de l&#8217;existence du conteneur, et qu&#8217;il puisse y accéder. Il est facile d&#8217;injecter le conteneur dans un service, en utilisant le type &laquo;&nbsp;container&raquo;&nbsp;, ou la facilité &laquo;&nbsp;containerAware&raquo;&nbsp;:</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;containerAwareService&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Service&quot;</span> <span class="re0">containerAware</span>=<span class="st0">&quot;true&quot;</span><span class="re2">/&gt;</span></span><br />
<span class="sc-1">&lt;!-- est exactement équivalent à--&gt;</span><br />
<span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;containerAwareService&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Service&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;setDiContainer&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">type</span>=<span class="st0">&quot;container&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/method<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div></div>
<p>Du coté de votre classe, si celle-ci doit récupérer le conteneur, elle à simplement à implémenter l&#8217;interface <em>SpiralDi_ContainerAware</em>. Lors de sa construction, la méthode <em>setDiContainer</em> sera directement appelée. </p>
<p>A noter que dans ce cas, il n&#8217;est pas nécessaire de définir votre service comme étant &laquo;&nbsp;ContainerAware&raquo;&nbsp;, le conteneur étant capable de le découvrir tout seul. </p>
<h2 id="toc-factories">Factories</h2>
<p>Il est également possible d&#8217;utiliser des Factory depuis le DI, pour générer un comportement comme celui ci</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="re0">$service</span> <span class="sy0">=</span> MyServiceFactory<span class="sy0">::</span><span class="me2">createService</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<p>Le code XML correspondant est le suivant:</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;serviceFactory&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;factory&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;MyServiceFactory&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;createService&quot;</span> <span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div></div>
<p>Cela peut s&#8217;avérer pratique pour récupérer vos anciennes implémentations du pattern Singleton entres autres&#8230;</p>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;singleton&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;factory&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;Mysingleton&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;getInstance&quot;</span> <span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span></div></div>
<h2 id="toc-telechargez-le">Téléchargez le ! </h2>
<p>Convaincu ? Pour récupérer la dernière version de SpiralDi, vous avez le choix entre plusieurs solutions:</p>
<h3 id="toc-via-le-depot-mercurial">Via le dépôt mercurial</h3>
<div class="codecolorer-container bash notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">hg clone https:<span class="sy0">//</span>ametaireau<span class="sy0">@</span>bitbucket.org<span class="sy0">/</span>ametaireau<span class="sy0">/</span>spiraldi<span class="sy0">/</span></div></div>
<h3 id="toc-via-les-archives">Via les archives</h3>
<p>Le code est disponible en <a href="http://bitbucket.org/ametaireau/spiraldi/get/tip.zip">zip</a>, <a href="http://bitbucket.org/ametaireau/spiraldi/get/tip.gz">gz</a> ou <a href="http://bitbucket.org/ametaireau/spiraldi/get/tip.bz2">bz2</a></p>
<p>Vous pouvez aussi aller <a href="http://bitbucket.org/ametaireau/spiraldi/">jeter directement un oeil au dépot</a>.<br />
Et voila! Vous avez de quoi vous amuser ! Pour toute demande de fonctionnalité, rapport de bug etc, <a href="http://bitbucket.org/ametaireau/spiraldi/issues/new/">n&#8217;hésitez surtout pas</a>!</p>
<h2 id="toc-et-ailleurs">Et ailleurs ?</h2>
<p>SpiralDi n&#8217;est bien évidemment pas le seul Conteneur Léger écrit en PHP. Depuis peu, ces derniers commencent d&#8217;ailleurs à fleurir sur la toile. Les frameworks Symfony et Flow3<sup>1</sup> leur font d&#8217;ailleurs la part belle, et c&#8217;est tant mieux! Quelques alternatives possibles au conteneur de Spiral donc:</p>
<ul>
<li><a href="http://svn.symfony-project.com/components/dependency_injection/">Le service container de symfony</a></li>
<li><a href="http://github.com/beberlei/yadif/tree/master">Yadim</a></li>
<li><a href="http://flow3.typo3.org/documentation/reference/object/">Flow3 Objects</a></li>
<li><a href="http://www.beberlei.de/sphicy/">Sphicy</a></li>
</ul>
<h2 id="toc-lectures-interessantes">Lectures intéressantes</h2>
<p>Si vous souhaitez aller plus loin, voici quelques lectures intéressantes sur le sujet de l&#8217;injection de dépendances:</p>
<ul>
<li><a href="http://www.martinfowler.com/articles/injection.html">L&#8217;article de Martin Fowler sur l&#8217;injection de dépendances</a></li>
<li>La série d&#8217;articles de Fabien potencier (<a href="http://fabien.potencier.org/article/11/what-is-dependency-injection">1</a>,<a href="http://fabien.potencier.org/article/12/do-you-need-a-dependency-injection-container">2</a>,<a href="http://fabien.potencier.org/article/13/introduction-to-the-symfony-service-container">3</a>,<a href="http://fabien.potencier.org/article/14/symfony-service-container-using-a-builder-to-create-services">4</a>,<a href="http://github.com/fabpot/Pimple/tree/master">5</a>)</li>
<li>Celle de Padraic Brady (<a href="http://blog.astrumfutura.com/archives/394-The-Case-For-Dependency-Injection-Part-1.html">1</a>,<a href="http://blog.astrumfutura.com/archives/395-The-Case-For-Dependency-Injection-Part-2.html">2</a>) </li>
<li><a href="http://www.dotnetguru.org/articles/dossiers/ioc/ioc.htm">Les conteneurs légers du futur</a>, par Sami Jabber</li>
</ul>
<ol class="footnotes"><li id="footnote_0_189" class="footnote">Il est tout nouveau, tout beau, en PHP 5.3, utilise l&#8217;AOP, la persistance <em>Domain Model</em> &#8230; et l&#8217;injection de dépendances! A suivre de très près: <a href="http://flow3.typo3.org/">Flow3 </a></li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.notmyidea.org/article/fr-introduction-to-spiral-dependency-injection-container-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introduction à l&#8217;injection de dépendances: le cas du singleton.</title>
		<link>http://www.notmyidea.org/article/dependency-injection-singleton-design-pattern-ioc-dendencies-dependences/</link>
		<comments>http://www.notmyidea.org/article/dependency-injection-singleton-design-pattern-ioc-dendencies-dependences/#comments</comments>
		<pubDate>Mon, 25 May 2009 14:36:58 +0000</pubDate>
		<dc:creator>Alexis Metaireau</dc:creator>
				<category><![CDATA[Architecture logicielle]]></category>
		<category><![CDATA[Injection de dépendances]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[singleton]]></category>
		<category><![CDATA[spiral]]></category>

		<guid isPermaLink="false">http://www.notmyidea.org/?p=67</guid>
		<description><![CDATA[L&#8217;architecture logicielle est un des aspects du développement qui m&#8217;intéresse particulièrement. Ça fait d&#8217;ailleurs un bout de temps que l&#8217;idée d&#8217;un article à propos des dépendances (de l&#8217;injection de dépendances) et du cas du singleton me trotte dans la tête, alors, le voici:
Avant tout, il faut bien comprendre que sans contexte il n&#8217;existe pas de [...]]]></description>
			<content:encoded><![CDATA[<p>L&#8217;architecture logicielle est un des aspects du développement qui m&#8217;intéresse particulièrement. Ça fait d&#8217;ailleurs un bout de temps que l&#8217;idée d&#8217;un article à propos des dépendances (de l&#8217;injection de dépendances) et du cas du singleton me trotte dans la tête, alors, le voici:</p>
<p>Avant tout, il faut bien comprendre que sans contexte il n&#8217;existe pas de manière plus censée qu&#8217;une autre pour construire une application. Il existe par contre un ensemble de bonnes pratiques qu&#8217;il est bon de connaitre et d&#8217;appliquer, dans la plus large mesure possible. Ces pratiques sont souvent mal connues, et nombre d&#8217;entre elles sont appliquées à la va vite.</p>
<p>Nous allons tenter d&#8217;expliquer ici pourquoi et comment l&#8217;implémentation la plus rependue du singleton favorise la création de dépendances, et comment nous pouvons y remédier, grâce à l&#8217;injection de dépendances.<br />
<span id="more-67"></span></p>
<h3 id="toc-le-singleton">Le singleton</h3>
<div id="attachment_140" class="wp-caption alignright" style="width: 160px"><img class="size-thumbnail wp-image-140" title="singleton" src="http://www.notmyidea.org/wp-content/uploads/2009/05/singleton-150x150.jpg" alt="Le singleton, à l'origine de dépendances" width="150" height="150" /><p class="wp-caption-text">Le singleton, à l&#39;origine de dépendances</p></div>
<p>Le Singleton est un patron de conception (souvent le premier patron de conception qui nous est présenté) qui doit être appliqué avec précaution. Son utilisation est souvent mal comprise et celui ci peut être considéré à tort comme une solution &laquo;&nbsp;miracle&raquo;&nbsp; pour accéder facilement à un objet, comme on le ferait d&#8217;une variable globale. On dit d&#8217;ailleurs aussi qu&#8217;il s&#8217;agit de l&#8217;<em>antipattern</em> singleton, à raison. Pourquoi ?</p>
<p>Très rapidement, un singleton est une classe dont il existe un nombre défini d&#8217;instances. Typiquement, le singleton est utilisé afin de réduire le nombre possible d&#8217;instances d&#8217;une classe à une seule. Cela peut être très utile, et est utilisé dans de nombreux cas à bon escient (je pense par exemple à l&#8217;accès à une base de données).</p>
<p>Un des défauts majeur de ce motif, est l&#8217;implémentation la plus souvent présentée, qui va de paire avec l&#8217;usage de méthodes statiques pour récupérer une instance de la classe. Pour mieux comprendre, voici l&#8217;implémentation type, en PHP (le motif est sensiblement le même dans de nombreux langages):</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">class</span> DbConnection_MySql <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">private</span> <a href="http://www.php.net/static"><span class="kw3">static</span></a> <span class="re0">$_instance</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw2">function</span> __construct <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw2">public</span> <a href="http://www.php.net/static"><span class="kw3">static</span></a> <span class="kw2">function</span> getInstance <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="br0">&#40;</span><span class="kw2">self</span><span class="sy0">::</span><span class="re0">$_instance</span> instanceof <span class="kw2">self</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span><span class="sy0">::</span><span class="re0">$_instance</span> <span class="sy0">=</span> <span class="kw2">new</span> <span class="kw2">self</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">self</span><span class="sy0">::</span><span class="re0">$_instance</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> connect<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// do some stuff</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p>Ici, pour récupérer l&#8217;instance de la classe, il est nécessaire de faire appel à la méthode statique <em>getInstance </em>de la classe <em>DbConnection_Mysql</em>.</p>
<p>Il est alors nécessaire, dans la classe utilisatrice du singleton (imaginons qu&#8217;il s&#8217;agisse d&#8217;une classe User), de <em>hardcoder</em> le nom de la classe DbConnection_Mysql, la classe A devenant alors <span style="text-decoration: underline;">dépendante</span> de cette implémentation particulière du singleton.</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">class</span> User<span class="br0">&#123;</span><br />
<br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// dépendance avec la classe DbConnection</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$dbc</span> <span class="sy0">=</span> DbConnection<span class="sy0">::</span><span class="me2">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p>Avec cette implémentation, il est impossible de changer la classe en charge de la connexion à la base de données sans modifier le code. Imaginons que nous souhaitons utiliser la classe <em>DbConnection_Oracle</em> par exemple, nous sommes bloqués. Il s&#8217;agit d&#8217;une problème de conception, et peut faire perdre un temps important lors du développement.</p>
<h3 id="toc-inversion-de-controle-injection-de-dependances">Inversion de contrôle / Injection de dépendances</h3>
<p>Comme nous venons de le voir, le singleton, ou plutôt, cette implémentation du singleton, introduit et favorise les dépendances entre nos classes.</p>
<p>Une des solutions possible est d&#8217;inverser le flux de contrôle de notre application: au lieu que ce soit la classe <em>User</em> qui appelle directement <em>DbConnection_Mysql</em>, celui ci peut être crée en amont, pour être ensuite injecté dans la classe qui souhaite l&#8217;utiliser. De cette manière,  Ce principe à un nom, il s&#8217;agit de <span style="text-decoration: underline;">l&#8217;injection de dépendances</span>.</p>
<h4 id="toc-theorie">Théorie</h4>
<p><em>Alice</em> a besoin d&#8217;une Glace pour la <em>manger()</em>.<br />
<em>Alice</em> aime les <em>GlaceALaFraise</em>&#8230; Si on donne de l&#8217;argent à <em>Alice</em> elle achète systématiquement une <em>GlaceALaFraise</em>. <em>Alice</em> est bloquée au seul parfum &laquo;&nbsp;fraise des bois&raquo;&nbsp; aussi savoureux soit-il.</p>
<p>Pour lui faire découvrir de nouvelles saveurs sa <em>Maman</em> décide de ne plus laisser <em>Alice</em> choisir sa <em>Glace</em> elle-même, mais se charge de choisir pour elle une <em>GlaceAuPaté</em>. </p>
<p>Quels que soit les goûts d&#8217;<em>Alice</em>, une <em>GlaceAuPaté</em> reste une <em>Glace</em>, et donc <em>Alice</em> est tout à fait à même de la <em>manger()</em><sup>1</sup>.</p>
<p>Le concept exposé ici est connu comme le <em><a href="http://en.wikipedia.org/wiki/Hollywood_principle">principe d&#8217;Holywood</a></em>: &laquo;&nbsp;Ne vous appelez pas vous même, nous vous appellerons&raquo;&nbsp;.</p>
<p>Ce qu&#8217;il faut retenir, c&#8217;est qu&#8217;<em>Alice</em> peut, si elle le souhaite, <em>manger()</em> tout type de <em>Glace</em>, même si au départ <em>Alice</em> n&#8217;à besoin de <em>manger()</em> q&#8217;une <em>GlaceALaFraise</em>. Nous favorisons ici la réutilisations du code: nous pouvons réutiliser Alice facilement et substituer sa <em>Glace</em> par une autre facilement.</p>
<h4 id="toc-application-a-notre-exemple">Application à notre exemple</h4>
<p>Reprenons l&#8217;exemple des utilisateurs et de l&#8217;utilisation de la DbConnection pour y appliquer ce principe d&#8217;inversion de contrôle. Notre code ressemblerait alors à quelque chose dans cet esprit:</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="re0">$dbc</span> <span class="sy0">=</span> <span class="kw2">new</span> DbConnection_Default<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$user</span> <span class="sy0">=</span> <span class="kw2">new</span> ClassA_Default<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$user</span><span class="sy0">-&gt;</span><span class="me1">setDbConnection</span><span class="br0">&#40;</span><span class="re0">$dbc</span><span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<p>Avec les deux interfaces/implémentations suivantes pour DbConnection et User:</p>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px;height:500px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">// Interfaces</span><br />
<span class="kw2">interface</span> DbConnection <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="re0">$host</span><span class="sy0">,</span> <span class="re0">$user</span><span class="sy0">,</span> <span class="re0">$password</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw2">function</span> connect<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">interface</span> User<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">function</span> setDbConnection<span class="br0">&#40;</span>DbConnection<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="co1">// Implementations</span><br />
<span class="kw2">class</span> DbConnection_Mysql implements DbConnection<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="re0">$host</span><span class="sy0">,</span> <span class="re0">$user</span><span class="sy0">,</span> <span class="re0">$password</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// store parameters into the object</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> connect<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// connect to the database</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw2">class</span> User_Default implements User<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> setDbConnection<span class="br0">&#40;</span>DbConnection <span class="re0">$dbc</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// store $dbc into the object</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p>Ici, il subsiste des dépendances dans le code. Il s&#8217;agit de dépendances vis à vis de contrats (interfaces) et non d&#8217;implémentations données (classes), puisque j&#8217;ai choisi d&#8217;utiliser le paradigme de <a href="http://fr.wikipedia.org/wiki/Programmation_par_contrat">programmation par contrats</a>.</p>
<p>Nous avons parlé de singleton et de création de dépendances, mais l&#8217;injection de dépendances est applicable à tout type de classes, et devrait d&#8217;ailleurs être utilisé dans la plupart des projet d&#8217;importante envergure.</p>
<h3 id="toc-utilisation-dun-conteneur">Utilisation d&#8217;un conteneur</h3>
<div id="attachment_170" class="wp-caption alignright" style="width: 197px"><img src="http://www.notmyidea.org/wp-content/uploads/2009/05/exemple.png" alt="schéma des dépendances entre nos classes" title="exemple" width="187" height="155" class="size-full wp-image-170 alignleft" /><p class="wp-caption-text">schéma des dépendances entre nos classes</p></div>
<p>Pour aller un peu plus loin, il peut être utile et efficace de déléguer la tâche de création des objets à un conteneur. Il s&#8217;agit d&#8217;une classe, en charge de la création de tous les objets, ce dernier pouvant résoudre les dépendances nécessaires à la création de l&#8217;objet souhaité.</p>
<p>Nous avons donc le schéma de dépendances décrit à gauche. Une fois ces informations fournies au conteneur (via un fichier de configuration), nous pouvons facilement récupérer l&#8217;object <em>User_Default</em> en le demandant à notre conteneur:</p>
<div class="codecolorer-container text notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">$container-&gt;user</div></div>
<p>. Ce dernier se charge alors de créer l&#8217;ensemble des dépendances de cet objet (un objet de la classe DbConnection_Mysql ici). Plutôt sympa, non ?</p>
<p>Pour faire en sorte que la classe d&#8217;accès aux données soit un singleton, c&#8217;est le schéma qu&#8217;il faut alors modifier (via le fichier de configuration ici.)</p>
<p>Ici, j&#8217;ai essentiellement parlé de dépendances entre classes. Cependant, de la même manière, il est possible de contrôler tous les arguments passés à nos objets, qu&#8217;il s&#8217;agisse de tableaux, de chaines de caractère ou autres.</p>
<h3 id="toc-moi-aussi-jen-veux-spiral-di-container">Moi aussi j&#8217;en veux ! Spiral Di Container</h3>
<p>Pour mon usage personnel, j&#8217;ai développé un injecteur de dépendances flexible, permettant d&#8217;appliquer ce modèle à mes futurs développements. Il existe déjà des projets similaires, mais ces derniers font un usage trop abusif &#8211; à mon gout &#8211; du mécanisme de réflexion, perdant alors grandement en performance.</p>
<p>Voyons comment nous pouvons utiliser le conteneur dans notre cas. Cela revient à créer le schéma de dépendances. Cela est possible pour le moment par 2 biais: via XML ou directement via php.</p>
<h4 id="toc-directement-via-php">Directement via php</h4>
<div class="codecolorer-container php notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="re0">$fluent</span><br />
<span class="sy0">-&gt;</span><span class="me1">registerService</span><span class="br0">&#40;</span><span class="st_h">'user'</span><span class="sy0">,</span> <span class="st_h">'User_Default'</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="sy0">-&gt;</span><span class="me1">call</span><span class="br0">&#40;</span><span class="st_h">'setDbConnection'</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">withServices</span><span class="br0">&#40;</span><span class="st_h">'dbc'</span><span class="br0">&#41;</span><br />
<span class="sy0">-&gt;</span><span class="me1">registerService</span><span class="br0">&#40;</span><span class="st_h">'dbc'</span><span class="sy0">,</span> <span class="st_h">'DbConnection_Mysql'</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="sy0">-&gt;</span><span class="me1">construct</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">with</span><span class="br0">&#40;</span><span class="st_h">'localhost'</span><span class="sy0">,</span> <span class="st_h">'root'</span><span class="sy0">,</span> <span class="st_h">''</span><span class="br0">&#41;</span></div></div>
<h4 id="toc-via-un-fichier-xml">Via un fichier XML</h4>
<div class="codecolorer-container xml notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;container<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;user&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;User_Default&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;setDbConnection&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;dbc&quot;</span> <span class="re0">service</span>=<span class="st0">&quot;true&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/method<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;service</span> <span class="re0">name</span>=<span class="st0">&quot;dbc&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;DbConnection_Mysql&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;method</span> <span class="re0">name</span>=<span class="st0">&quot;__construct&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;localhost&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;root&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;argument</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/method<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/service<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/container<span class="re2">&gt;</span></span></span></div></div>
<p>Il est à noter que le fichier XML à été directement généré via le <em>Dumper</em> Xml, en utilisant le schema.</p>
<p>Si vous êtes interessé pour regarder plus en détail le fonctionnement de ce conteneur, les sources sont d&#8217;ores et déjà disponibles via le framework de travail spiral, disponible via <a href="http://bitbucket.org/ametaireau/spiral-php52/src/di/">son dépot mercurial</a>.</p>
<p>L&#8217;injecteur de dépendances est présent dans la partie /core/Di de l&#8217;architecture. Une version standalone devrait bientôt voir le jour.</p>
<p>Si cet article vous à plu, je publierais prochainement une série d&#8217;article expliquant en détail comment utiliser un conteneur de dépendances, en m&#8217;appuyant sur des exemples concrets que j&#8217;ai pu rencontrer.</p>
<p>Ah, et j&#8217;oubliais, un grand merci aux relecteurs pour votre aide précieuse ! (Fred, David, Florent, Joel, Nico &#8230;)</p>
<ol class="footnotes"><li id="footnote_0_67" class="footnote">Merci Frédéric pour ton super exemple !</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.notmyidea.org/article/dependency-injection-singleton-design-pattern-ioc-dendencies-dependences/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Installation de PHP 5.3 en tant que CGI</title>
		<link>http://www.notmyidea.org/article/php-53-cgi-installation/</link>
		<comments>http://www.notmyidea.org/article/php-53-cgi-installation/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 01:34:33 +0000</pubDate>
		<dc:creator>Alexis Metaireau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[CGI]]></category>
		<category><![CDATA[php5.3]]></category>

		<guid isPermaLink="false">http://www.notmyidea.org/?p=120</guid>
		<description><![CDATA[La RC1 de PHP 5.3 est disponible depuis peu sur le site de php. J&#8217;ai sauté sur l&#8217;occasion pour la télécharger et l&#8217;installer sur ma machine de développement, pour pouvoir profiter des nombreuses et alléchantes nouvelles fonctionnalités offertes par cette version.
Ayant besoin de garder une version de PHP 5.2 disponible, j&#8217;ai choisi d&#8217;installer PHP 5.3 [...]]]></description>
			<content:encoded><![CDATA[<p>La <acronym title="Release Candidate">RC1</acronym> de PHP 5.3 est disponible depuis peu sur le site de php. J&#8217;ai sauté sur l&#8217;occasion pour la télécharger et l&#8217;installer sur ma machine de développement, pour pouvoir profiter des nombreuses et alléchantes nouvelles fonctionnalités offertes par cette version.</p>
<p>Ayant besoin de garder une version de PHP 5.2 disponible, j&#8217;ai choisi d&#8217;installer PHP 5.3 en tant que CGI pour Apache. Rien de très compliqué, mais si je peux vous éviter de tourner en rond, voila comment j&#8217;ai procédé sur un système à base de debian (ubuntu ici).<br />
<span id="more-120"></span></p>
<p>On commence par télécharger la dernière archive sur snaps.php.net:</p>
<div class="codecolorer-container bash notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">wget</span> http:<span class="sy0">//</span>snaps.php.net<span class="sy0">/</span>php5.3-latest.tar.gz</div></div>
<p>On l&#8217;extrait:</p>
<div class="codecolorer-container bash notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">tar</span> <span class="re5">-xvf</span> php5.3-latest.tar.gz</div></div>
<p>On compile ..</p>
<div class="codecolorer-container bash notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw3">cd</span> php5.3-<span class="nu0">200903291630</span><br />
.<span class="sy0">/</span>configure<br />
<span class="kw2">sudo</span> <span class="kw2">make</span> <span class="sy0">&amp;</span>amp;<span class="sy0">&amp;</span>amp; <span class="kw2">sudo</span> <span class="kw2">make</span> <span class="kw2">install</span></div></div>
<p>C&#8217;est quasiment prêt, les fichiers binaires ont étés crées dans /usr/local/bin/ , il ne reste plus qu&#8217;à activer le module actions pour apache (pour pouvoir utiliser les CGIs):</p>
<div class="codecolorer-container bash notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">sudo</span> a2enmod actions</div></div>
<p>et à spécifier l&#8217;emplacement de nos cgis à Apache:</p>
<div class="codecolorer-container bash notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">sudo</span> <span class="kw3">echo</span> <span class="st_h">'ScriptAlias /cgi-bin/ /usr/local/bin/'</span> <span class="sy0">&amp;</span>gt;<span class="sy0">&amp;</span>gt; <span class="sy0">/</span>etc<span class="sy0">/</span>apache2<span class="sy0">/</span>apache2.conf</div></div>
<p>Voila, il ne vous reste plus qu&#8217;à relancer apache à coup de</p>
<div class="codecolorer-container text notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">apachectl restart</div></div>
<p>et c&#8217;est parti !</p>
<p>Maintenant, pour utiliser PHP 5.3 au lieu de la version installée par défaut, il vous faudra créer un htaccess avec le contenu suivant:</p>
<div class="codecolorer-container bash notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="bash codecolorer" style="font-family:Monaco,Lucida Console,monospace">AddHandler x-httpd-php5 .php<br />
Action x-httpd-php5 <span class="sy0">/</span>cgi-bin<span class="sy0">/</span>php-cgi</div></div>
<p>A nous les joies de php 5.3 !<br />
<img class="aligncenter size-full wp-image-127" title="php-53" src="http://www.notmyidea.org/wp-content/uploads/2009/03/php-53.png" alt="php-53" width="400" height="378" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.notmyidea.org/article/php-53-cgi-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comparatif des bibliothèques graphiques php</title>
		<link>http://www.notmyidea.org/article/bibliotheques-graphiques-comparatif-php-libs-graphics/</link>
		<comments>http://www.notmyidea.org/article/bibliotheques-graphiques-comparatif-php-libs-graphics/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 10:53:13 +0000</pubDate>
		<dc:creator>Alexis Metaireau</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[ez-components]]></category>

		<guid isPermaLink="false">http://www.notmyidea.org/?p=69</guid>
		<description><![CDATA[J&#8217;ai travaillé récemment sur une solution pour générer des graphiques efficacement, tout en aillant le meilleur rendu possible, et ce pour des graphiques devant utiliser beaucoup de valeurs (de l&#8217;ordre de 5000 pour un graphique). 
Je regroupe ici les résultats de mon étude, en espérant faire un petit état des lieux des différentes bibliothèques de [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;ai travaillé récemment sur une solution pour générer des graphiques efficacement, tout en aillant le meilleur rendu possible, et ce pour des graphiques devant utiliser beaucoup de valeurs (de l&#8217;ordre de 5000 pour un graphique). </p>
<p>Je regroupe ici les résultats de mon étude, en espérant faire un petit état des lieux des différentes bibliothèques de génération de graphiques existantes, en tentant des les comparer. Volontairement, je ne désigne pas de meilleure bibliothèque, puisque cela dépends fortement du besoin qui l&#8217;accompagne.</p>
<p>J&#8217;ai tenté de faire un tour des bibliothèques qui me semblaient intéressantes, si toutefois vous connaissez une bibliothèque qui aurait sa place ici, je me ferais un plaisir de l&#8217;ajouter au comparatif. </p>
<p><span id="more-69"></span></p>
<h2>Table des matières</h2>
<div class="toc">
<ol>
<li><a href="http://www.notmyidea.org/article/bibliotheques-graphiques-comparatif-php-libs-graphics/#toc-criteres-de-comparaison">Critères de comparaison</a></li>
<li><a href="http://www.notmyidea.org/article/bibliotheques-graphiques-comparatif-php-libs-graphics/#toc-solutions-existantes-et-descriptions">Solutions existantes et descriptions</a>
<ol>
<li><a href="http://www.notmyidea.org/article/bibliotheques-graphiques-comparatif-php-libs-graphics/#toc-pchart">pChart</a></li>
<li><a href="http://www.notmyidea.org/article/bibliotheques-graphiques-comparatif-php-libs-graphics/#toc-phplot">phPlot</a></li>
<li><a href="http://www.notmyidea.org/article/bibliotheques-graphiques-comparatif-php-libs-graphics/#toc-ezcomponents-graph">ezComponents: Graph</a></li>
</ol>
</li>
<li><a href="http://www.notmyidea.org/article/bibliotheques-graphiques-comparatif-php-libs-graphics/#toc-benchmarks">Benchmarks</a></li>
<li><a href="http://www.notmyidea.org/article/bibliotheques-graphiques-comparatif-php-libs-graphics/#toc-tableau-comparatif">Tableau comparatif</a></li>
</ol>
</div>
<h2 id="toc-criteres-de-comparaison">Critères de comparaison</h2>
<p>Ce comparatif se base sur les critères suivants:</p>
<ul>
<li>configuration (degré et facilité)</li>
<li>Facilité d&#8217;ajout de nouveaux types de graphiques</li>
<li>Qualité du code / maintenabilité</li>
<li>les bibliothèques doivent êtres orienté objet</li>
<li>générer les graphiques &laquo;&nbsp;coté&raquo;&nbsp; serveur (pas d&#8217;application flash ou javascript donc)</li>
<li>être encore maintenue par ses auteurs</li>
</ul>
<h2 id="toc-solutions-existantes-et-descriptions">Solutions existantes et descriptions</h2>
<h3 id="toc-pchart">pChart</h3>
<h4 id="toc-descriptif">Descriptif</h4>
<p><a href="http://pchart.sourceforge.net">pChart</a> est une bibliothèque php qui comporte 3 classes:</p>
<ul>
<li><strong>pChart</strong> qui est en charge de construire les graphiques. Cette classe est fournie avec 2 types de methodes: celles qui permettent de créer directement des graphiques de <em>haut niveau</em>, et celles de <em>bas niveau</em> qui permettent de tracer les lignes, ellipses etc.</li>
<li><strong>pData</strong> est en charge de la gestion des données. Elle fournit un certain nombre de méthodes qui permettent la manipulation de données pour les graphiques.</li>
<li>Un système de cache: <strong>pCache</strong></li>
</ul>
<h4 id="toc-avantages">Avantages</h4>
<p>pChart fournit des graphiques de qualité, et une grande abstraction vis à vis des méthodes de bas niveau qu&#8217;elle offre. Par exemple, les méthodes fournies pour générer un graphique de type <em>Pie</em> sont parlantes. De plus, une bonne séparation des couches est faite: pData, pChart et pCache on chacun leur rôle et s&#8217;y tiennent.</p>
<h4 id="toc-inconvenients">Inconvénients</h4>
<p>pChart n&#8217;est pas forcement pensé pour être étendu de la meilleure manière. Ainsi, pour ajouter de fonctionnalités de bas niveau par exemple, tel le changement de format du fichier de sortie, il faut réécrire les méthodes de la classe pChart afin qu&#8217;elles supportent ce nouveau format (ie. Il n&#8217;existe pas de système de <em>&laquo;&nbsp;driver&raquo;&nbsp;</em>). Aussi, le code en lui même n&#8217;est pas beaucoup commenté, ce qui constitue un frein à la compréhension de celui ci. Par defaut, pChart ne gère pas le SVG.</p>
<h4 id="toc-exemple">Exemple</h4>
<pre class="brush: php;">
// Dataset definition
$DataSet = new pData();
$DataSet-&gt;AddPoint(array(10,2,3,5,3),'Serie1');
$DataSet-&gt;AddPoint(array('Jan','Feb','Mar','Apr','May'),'Serie2');
$DataSet-&gt;AddAllSeries();
$DataSet-&gt;SetAbsciseLabelSerie('Serie2');

// Initialise the graph
$Test = new pChart(300,200);
$Test-&gt;drawFilledRoundedRectangle(7,7,293,193,5,240,240,240);
$Test-&gt;drawRoundedRectangle(5,5,295,195,5,230,230,230);

// Draw the pie chart
$Test-&gt;setFontProperties('Fonts/tahoma.ttf',8);
$Test-&gt;drawFlatPieGraph($DataSet-&gt;GetData(),$DataSet-&gt;GetDataDescription(),120,100,60,PIE_PERCENTAGE,10);
$Test-&gt;drawPieLegend(230,15,$DataSet-&gt;GetData(),$DataSet-&gt;GetDataDescription(),250,250,250);

$Test-&gt;Render('example13.png');
</pre>
<div class="acenter"><img class="aligncenter size-full wp-image-71" title="pchart pie" src="http://www.notmyidea.org/wp-content/uploads/2009/03/pchart.png" alt="pchart pie" width="300" height="200" /></div>
<h3 id="toc-phplot">phPlot</h3>
<h4 id="toc-descriptif1">Descriptif</h4>
<p><a href="http://sourceforge.net/projects/phplot/">phPlot</a> est une bibliothèque qui comporte une seule classe en charge de la génération des graphiques. Cette classe interagit avec l&#8217;extension php <em>GD</em> pour construire des graphiques. Les méthodes de cette classe sont là aussi séparés en méthode de bas et haut niveau.</p>
<h4 id="toc-avantages1">Avantages</h4>
<p>La bibliothèque tiens dans une seule classe, ce qui peut s&#8217;avérer pratique, une documentation exhaustive est fournie sur internet</p>
<h4 id="toc-inconvenients1">Inconvénients</h4>
<p>Étant basée sur GD pour la génération des graphiques, il est semble assez difficile de rajouter un format de sortie facilement: la solution n&#8217;est pas pensée pour être extensible à ce niveau là. La classe en question n&#8217;est pas facile à étendre ou modifier. De plus les graphiques rendus ne sont pas très esthétiques</p>
<h4 id="toc-exemple1">Exemple</h4>
<pre class="brush: php;">
$plot = new PHPlot('300','200');
$data = array(
    array('Jan',10),
    array('Feb', 2),
    array('Mar', 3),
    array('Apr', 5),
    array('May', 3)
);
$plot-&gt;SetPlotType('pie');
$plot-&gt;SetDataType('text-data-single');
$plot-&gt;SetDataValues($data);
foreach ($data as $row)
  $plot-&gt;SetLegend(implode(': ', $row));

$plot-&gt;DrawGraph();
</pre>
<div class="acenter"><img class="aligncenter size-full wp-image-72" title="phplot" src="http://www.notmyidea.org/wp-content/uploads/2009/03/phplot.png" alt="phplot" width="300" height="200" /></div>
<h3 id="toc-ezcomponents-graph">ezComponents: Graph</h3>
<h4 id="toc-descriptif2">Descriptif</h4>
<p>Les <a href="http://ezcomponents.org/docs/api/latest/introduction_Graph.html">ezComponents</a> sont des composants originellement utilisés pour la plate forme de publication ezPublish, mais visant dès le début à ne pas être dépendant de cette plate forme de publication. Les ezComponents forment à eux seuls un ensemble de briques logicielles prêtes à l&#8217;usage, un peu comme peut l&#8217;être le Zend Framework.</p>
<h4 id="toc-avantages2">Avantages</h4>
<p>Cette bibliothèque, ainsi que la totalité des ezComponents, vise à être utilisée sur des sites importants. Pour cette raison, un support existe sur ces solutions, et les composants seront probablement maintenus durant une période importante. L&#8217;ensemble des ezComponents est fourni avec une documentation très complète, des exemples, des tests unitaires, et un diagramme de classe (UML), qui indique que le code est réellement pensé orienté objet. Chaque classe à alors une utilisation bien précise, l&#8217;application étant réellement bien découplée. Cette bibliothèque est également fournie avec un support natif du SVG, grâce à un système de plugin de sortie. Par défaut, le système est prévu pour être extensible; ainsi, pour ajouter un nouveau type de graphique par exemple, l&#8217;utilisation du système d&#8217;héritage permet de gagner du temps. La configuration peut être très poussée en restant lisible.</p>
<h4 id="toc-inconvenients2">Inconvénients</h4>
<p>Tous les ezComponents ont une dépendance vis à vis de la classe ezBase. De plus, utiliser ce composant induit le  chargement d&#8217;un grand nombre de classes, et donc de fichiers. Par défaut, ce composant n&#8217;as pas de système de cache. Il en existe par contre un dans les ezComponents. Etre complètement orienté objet peut aussi s&#8217;avérer être un inconvénient: une bibliothèque graphique peut être amenée à afficher un nombre important de valeurs. Cela signifie dans ce cas là, passer dans un nombre aussi important de méthodes et le temps de rendu peut s&#8217;avérer réellement long (voir la section benchmarks à la fin de cet article)</p>
<h4 id="toc-exemple2">Exemple</h4>
<pre class="brush: php;">// Create the graph
$graph = new ezcGraphPieChart();

// Add the data and hilight norwegian data set
$graph-&gt;data['months'] = new ezcGraphArrayDataSet( array(
    'Jan' =&gt; 10,
    'Feb' =&gt; 2,
    'Mar' =&gt; 3,
    'Apr' =&gt; 5,
    'May' =&gt; 3
));

// Modify pie chart label to only show amount and percent
$graph-&gt;options-&gt;label = '%3$.0f%%';
$graph-&gt;options-&gt;font-&gt;maxFontSize = 10	;

// legend
$graph-&gt;legend-&gt;landscapeSize = .3;

// Use 2d renderer, and beautify it
$graph-&gt;renderer = new ezcGraphRenderer2d();
$graph-&gt;renderer-&gt;options-&gt;dataBorder = false;
$graph-&gt;renderer-&gt;options-&gt;pieChartGleam = .3;
$graph-&gt;renderer-&gt;options-&gt;pieChartGleamColor = '#FFFFFF';
$graph-&gt;renderer-&gt;options-&gt;pieChartGleamBorder = 1;
$graph-&gt;renderer-&gt;options-&gt;showSymbol = false;  

// set colors
$graph-&gt;palette = new ezcGraphPaletteEz();

// Output the graph with std SVG driver
$graph-&gt;render( 300, 200, 'ezGraph.svg' );</pre>
<div class='acenter'><object data="http://www.notmyidea.org/wp-content/uploads/2009/03/ezgraph.svg" type="image/svg+xml" height="200" width="300"></object></div>
<h2 id="toc-benchmarks">Benchmarks</h2>
<p>Maintenant ces différentes solutions sont présentées, il peut être intéressant de les comparer sur le plan rapidité. Voici un Petit comparatif au niveau rapidité. Si vous êtes curieux, vous pouvez <a href=' http://docs.notmyidea.org/benchs/charts.tar.gz'>télécharger les fichier source du benchmark</a>.</p>
<p>Les différentes valeurs utilisées sont les suivantes: (width, height, values)</p>
<pre class="brush: php;">
$configs['simple'] = array(400, 	300, 	range(0,10));
$configs['medium'] = array(500, 	500, 	range(0,100));
$configs['hard'] = array(1000, 1000, range(0,1000));
$configs['real'] = array(600, 200, include('_realData.php'));
</pre>
<p>Le fichier _realData.php contient retourne un tableau de quelques 1104 valeurs continues. Il se trouve aussi dans les sources disponibles plus haut.</p>
<p>Voici le résultat du test:</p>
<table>
<thead>
<tr>
<td></td>
<td>simple</td>
<td>medium</td>
<td>hard</td>
<td>real</td>
</tr>
</thead>
<tbody>
<tr>
<td>ezc</td>
<td>0.4</td>
<td>0.38</td>
<td>4.63</td>
<td>10</td>
</tr>
<tr class='odd'>
<td>pchart</td>
<td>0.8</td>
<td>0.66</td>
<td>2.36</td>
<td>1.91</td>
</tr>
<tr>
<td>phplot</td>
<td>0.08</td>
<td>0.05</td>
<td>0.32</td>
<td>0.33</td>
</tr>
<tr class='odd'>
<td>artichow</td>
<td>0.23</td>
<td>0.34</td>
<td>4.1</td>
<td>6.46</td>
</tr>
</tbody>
</table>
<h2 id="toc-tableau-comparatif">Tableau comparatif</h2>
<table>
<thead>
<tr>
<td></td>
<td>qualité du code</td>
<td>découplage</td>
<td>extensibilité</td>
<td>config (degré)</td>
<td>config (facilité)</td>
<td>qualité des graphs</td>
<td>temps de rendu</td>
<td>support du SVG</td>
</tr>
</thead>
<tbody>
<tr>
<td>pChart</td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/delete.png' alt='-'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/delete.png' alt='-'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/cross.png' alt='no'/></td>
</tr>
<tr class='odd'>
<td>PHPlot</td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/delete.png' alt='-'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/delete.png' alt='-'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/delete.png' alt='-'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/delete.png' alt='-'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/cross.png' alt='no'/></td>
</tr>
<tr>
<td>ezComponents</td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/><img src='http://www.notmyidea.org/wp-content/uploads/images/add.png' alt='+'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/delete.png' alt='-'/><img src='http://www.notmyidea.org/wp-content/uploads/images/delete.png' alt='-'/><img src='http://www.notmyidea.org/wp-content/uploads/images/delete.png' alt='-'/></td>
<td><img src='http://www.notmyidea.org/wp-content/uploads/images/tick.png' alt='yes'/></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.notmyidea.org/article/bibliotheques-graphiques-comparatif-php-libs-graphics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quelques nouvelles</title>
		<link>http://www.notmyidea.org/article/quelques-nouvelles/</link>
		<comments>http://www.notmyidea.org/article/quelques-nouvelles/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 17:42:06 +0000</pubDate>
		<dc:creator>Alexis Metaireau</dc:creator>
				<category><![CDATA[3615 MyLife]]></category>
		<category><![CDATA[Associatif]]></category>
		<category><![CDATA[toulouse]]></category>
		<category><![CDATA[Travail]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.notmyidea.org/?p=68</guid>
		<description><![CDATA[Même si l&#8217;activité sur ces carnets pourrait laisser penser le contraire, je travaille activement, et sur plein de projets !
Récemment, j&#8217;ai été embauché en tant que stagiaire dans une petite boite qui fait du développement d&#8217;applications web (que je différencie de la réalisation de sites web). Cette société, basée à Paris, vient d&#8217;ouvrir des locaux [...]]]></description>
			<content:encoded><![CDATA[<p>Même si l&#8217;activité sur ces carnets pourrait laisser penser le contraire, je travaille activement, et sur plein de projets !</p>
<p>Récemment, j&#8217;ai été embauché en tant que stagiaire dans une petite boite qui fait du développement d&#8217;applications web (que je différencie de la réalisation de sites web). Cette société, basée à Paris, vient d&#8217;ouvrir des locaux sur Toulouse, et j&#8217;ai la joie et le plaisir d&#8217;en profiter. Je m&#8217;amuse vraiment, et découvre le Zend Framework, tout en passant toujours pour un extremiste qui déteste les antipatterns<sup>1</sup>. Bref, une super équipe, des gens très interessants, et un stage de 6 mois qui débute très bien !</p>
<p>J&#8217;ai commencé les cours, après un mois de pré-cours intensifs<sup>2</sup>. Et pour l&#8217;instant, ça me déplait plutôt. Il faut dire que les matières abordées ne s&#8217;y prétaient pas beaucoup (Microsoft et Oracle : merci bonsoir). La semaine qui arrive annonce le début des cours de Java, qui semblent bien plus prométeurs<sup>3</sup>. Espérons.</p>
<p>Qui l&#8217;eut cru: on à repris le développement de spiral, qui décidément porte très bien son nom, vu le temps depuis lequel le projet traine. Des deadlines sont fixées, les idées toujours aussi bonnes, et la motivation au rendez vous. Quelques nuit de travail en perspective, mais qu&#8217;est ce que c&#8217;est bon d&#8217;échanger sur des <em>vrais</em> sujets de geek developpeurs fans de design patterns !</p>
<p>Depuis mon arrivée à Toulouse, je fait partie d&#8217;<a href="http://veracruz.over-blog.net/">une association naturaliste</a> basée sur l&#8217;université de ramonville<sup>4</sup>, avec laquelle j&#8217;ai pu lancer un projet de semaine de l&#8217;environnement<sup>5</sup>. Ca me prends pas mal de temps, mais je rencontre des gens géniaux, et ça me fait décrocher de ce satané écran ! D&#8217;ailleurs, la semaine de l&#8217;environnement à non pas lieu dans une ville, mais dans 8, et les associations en question sont fédérées autour du <a href="http://grappe.notmyidea.org">GRAPPE</a> (Groupement des Associations Porteuses de Projets en Environnement). Si vous aussi vous voulez lancer une semaine de l&#8217;environnement chez vous, contactez nous !</p>
<p>Plus recemment, nous avons eu l&#8217;idée de lancer une <a href="http://fr.wikipedia.org/wiki/AMAP">AMAP</a> étdudiante sur Toulouse. Si vous êtes interessés, faites moi signe, les réunions approchent !</p>
<ol class="footnotes"><li id="footnote_0_68" class="footnote"> ou qui adore les patterns,au choix. </li><li id="footnote_1_68" class="footnote"> ou pas, tout dépends les matières </li><li id="footnote_2_68" class="footnote"> avis aux trolleurs multiples et potentiels: oui, je crois sincérement que Java, c&#8217;est bien. Un peu lent, mais bien! Peut être que l&#8217;avenir me contredira. </li><li id="footnote_3_68" class="footnote"> qui n&#8217;est pas <strong>du tout </strong>à coté de mon école&#8230; </li><li id="footnote_4_68" class="footnote"> une semaine d&#8217;activités autour du thème de l&#8217;environnement, qui aura lieu du 16 au 22 Mars 2009 </li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.notmyidea.org/article/quelques-nouvelles/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Allez, au boulot !</title>
		<link>http://www.notmyidea.org/article/retour-a-lactivite/</link>
		<comments>http://www.notmyidea.org/article/retour-a-lactivite/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 13:22:57 +0000</pubDate>
		<dc:creator>Alexis Metaireau</dc:creator>
				<category><![CDATA[3615 MyLife]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[me me me me me]]></category>
		<category><![CDATA[toulouse]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.notmyidea.org/?p=65</guid>
		<description><![CDATA[Ca fait un bon moment que je n&#8217;ai pas pris le temps d&#8217;écrire ici, et pour cause, l&#8217;été fut chargé: réalisation de sites webs, utilisation intensive des molets1, et découverte des joies du foie gras2
Mais la rentrée pointe le bout de son nez (c&#8217;est une bonne chose!), et la reprise d&#8217;activités cérébrales ne devrait plus [...]]]></description>
			<content:encoded><![CDATA[<p>Ca fait un bon moment que je n&#8217;ai pas pris le temps d&#8217;écrire ici, et pour cause, l&#8217;été fut chargé: réalisation de sites webs, utilisation intensive des molets<sup>1</sup>, et découverte des joies du foie gras<sup>2</sup></p>
<p>Mais la rentrée pointe le bout de son nez (c&#8217;est une bonne chose!), et la reprise d&#8217;activités cérébrales ne devrait plus trop tarder. Comme d&#8217;habitude, petite liste des choses que j&#8217;aimerais bien faire cette année<sup>3</sup></p>
<ul>
<li>J&#8217;ai eu l&#8217;occasion de découvrir l&#8217;excellent framework web <a href="http://www.jelix.org">Jelix</a>, et de l&#8217;utiliser pour un projet (pas encore totalement terminé) web. Beaucoup de choses géniales, découverte de svn malgrès moi, et des tonnes d&#8217;idées à repiquer pour spiral en perspective<sup>4</sup>.</li>
<li>Trouver un designer digne de ce nom, sur Toulouse, avec lequel travailler, parce que mes clients commencent à trouver que mes sites ont une sale gueule (et ils ont raison&#8230;)</li>
<li>Trouver un <strong>vrai </strong>bouquin sur les <strong>designs patterns</strong>, <strong>en français</strong>, à mettre sur ma table de chevet.</li>
<li>Et puis, enfin, m&#8217;installer et découvrir Toulouse, puisque j&#8217;ai la chance de poursuivre mes études la bas. D&#8217;ailleurs, si vous êtes du coin, je suis pour une visite grandeur nature!</li>
</ul>
<p>Je profite de ce billet pour remercier ceux qui ont permis de faire de ma passion un gagne-pain le temps d&#8217;un été. L&#8217;expérience fut très enrichissante, et je vous en remercie chaleureusement.</p>
<ol class="footnotes"><li id="footnote_0_65" class="footnote">750km à vélo pour un mois de vacances inoubliable&#8230;</li><li id="footnote_1_65" class="footnote">En savourant du <a href="http://www.deezer.com/track/7226">Masada</a> sous le grand chapiteau de Jazz In Marciac!</li><li id="footnote_2_65" class="footnote">même si je sens que le temps va manquer&#8230;</li><li id="footnote_3_65" class="footnote">malgrès la puissance de jelix, je continue à m&#8217;obstiner à faire &laquo;&nbsp;mon mien&raquo;&nbsp;. Question de fierté peut être ? En tout cas il me reste &#8211; beaucoup &#8211; à apprendre</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.notmyidea.org/article/retour-a-lactivite/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Qu&#8217;est ce que GNU/Linux ? Retour aux origines</title>
		<link>http://www.notmyidea.org/article/quest-ce-que-gnulinux-retour-aux-origines/</link>
		<comments>http://www.notmyidea.org/article/quest-ce-que-gnulinux-retour-aux-origines/#comments</comments>
		<pubDate>Fri, 30 May 2008 11:17:49 +0000</pubDate>
		<dc:creator>Alexis Metaireau</dc:creator>
				<category><![CDATA[Libre]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[idéologie]]></category>
		<category><![CDATA[projet gnu]]></category>

		<guid isPermaLink="false">http://www.notmyidea.org/?p=64</guid>
		<description><![CDATA[Avec l&#8217;arrivée des distributions « grand public », GNU/Linux souffre d&#8217;un phénomène qui prend de plus en plus d&#8217;ampleur :
C&#8217;est parce que GNU/Linux est une solution de plus en plus largement diffusée et accessible que beaucoup de nouveaux utilisateurs s&#8217;y essayent. Trop souvent en oubliant qu&#8217;il s&#8217;agit du résultat du labeur de la communauté Libre. [...]]]></description>
			<content:encoded><![CDATA[<p>Avec l&#8217;arrivée des distributions « grand public », GNU/Linux souffre d&#8217;un phénomène qui prend de plus en plus d&#8217;ampleur :</p>
<p>C&#8217;est parce que GNU/Linux est une solution de plus en plus largement diffusée et accessible que beaucoup de nouveaux utilisateurs s&#8217;y essayent. Trop souvent en oubliant qu&#8217;il s&#8217;agit du résultat du labeur de la communauté Libre. C&#8217;est un phénomène qui se vérifie trop souvent, et j&#8217;en suis moi même la preuve : lorsque j&#8217;ai décidé de passer sous GNU/Linux, c&#8217;était plus par curiosité &#8211; parce que cela était amusant &#8211; que parce qu&#8217;il s&#8217;agissait d&#8217;une solution fonctionnant grâce et pour le logiciel libre. Ce n&#8217;est qu&#8217;au fur et à mesure de mes pérégrinations que j&#8217;ai cherché à approfondir  cette question qui me semble désormais essentielle.</p>
<p>Cela semble pourtant être une évidence : « J&#8217;utilise Linux, donc je sais de quoi il retourne ». Malheureusement, c&#8217;est assez souvent faux ! Parce qu&#8217;il est nécessaire  d&#8217;avoir une démarche personnelle vers le Logiciel libre pour en comprendre la grandeur, et pour saisir les messages d&#8217;ordre philosophique et politique (au sens noble du terme) qu&#8217;il engage<sup>1</sup>.</p>
<p>On compare trop souvent GNU/Linux à Windows, et c&#8217;est un tord: L&#8217;un n&#8217;est pas l&#8217;autre<sup>2</sup>, et les principes qui les régissent, même si ils suivent les même bases techniques (ce sont tous deux des systèmes d&#8217;exploitation voués aux mêmes finalités), sont complètement différents voir parfaitement opposés: l&#8217;un défends le logiciel libre tandis que l&#8217;autre s&#8217;inscrit dans une logique de profit économique, et de « programmation égoïste »<sup>3</sup>.<br />
Ce sont ces principes et cette idéologie, qui ont permis à GNU/Linux de devenir ce qu&#8217;il est. Cela à fonctionné <strong>parce qu&#8217;il s&#8217;agit d&#8217;un logiciel libre</strong>, permettant à chacun, à son échelle, de participer au projet comme il l&#8217;entends.</p>
<p>Il semble donc primordial de ne pas reléguer le logiciel libre à un simple contexte de développement, ayant permis de donner naissance au paysage libre actuel. C&#8217;est ce qui semble se passer, et la conséquence est simple: les contributions ne sont pas à hauteur du succès des différents projets<sup>4</sup>.</p>
<p>Le simple fait d&#8217;utiliser des logiciels libres ne suffit pas à contribuer à son évolution, il est nécessaire de s&#8217;y impliquer pour que cela fonctionne<sup>5</sup>. La déclaration d&#8217;un bug ou un simple retour utilisateur permettent alors de contribuer, à votre échelle.</p>
<p><strong>Avec GNU/Linux, vous avez le pouvoir de faire évoluer les choses, utilisez le !</strong></p>
<ol class="footnotes"><li id="footnote_0_64" class="footnote"><a href="http://www.gnu.org/philosophy/">le projet GNU</a> est une ressource intarissable à ce sujet</li><li id="footnote_1_64" class="footnote"><a href="http://www.commentcamarche.net/faq/sujet-7283-linux-n-est-pas-windows">Lire l&#8217;excellent article de Sébastien Sauvage à ce sujet</a></li><li id="footnote_2_64" class="footnote">au sens ou l&#8217;entends <a href="http://weinbergonwriting.blogspot.com"></a>Gerald Weinberg dans son ouvrage <a href="http://www.geraldmweinberg.com/Site/Programming_Psychology.html">The Psychology of Computer Programming</a></li><li id="footnote_3_64" class="footnote"><a href="http://www.chevrel.org/fr/carnet/index.php?2008/04/26/711-besoin-de-traducteurs-pour-l-aide-de-firefox-3-sur-supportmozillaorg">ça en fait d&#8217;ailleurs râler certains</a></li><li id="footnote_4_64" class="footnote">C&#8217;est d&#8217;ailleurs ce point qui est à l&#8217;origine des désaccords entre les partisans du Logiciel Libre et ceux de l&#8217;Open Source&#8230;</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.notmyidea.org/article/quest-ce-que-gnulinux-retour-aux-origines/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Convertir des albums encodés en .flac vers du .mp3</title>
		<link>http://www.notmyidea.org/article/convertir-des-albums-encodes-en-flac-vers-du-mp3/</link>
		<comments>http://www.notmyidea.org/article/convertir-des-albums-encodes-en-flac-vers-du-mp3/#comments</comments>
		<pubDate>Mon, 26 May 2008 16:51:30 +0000</pubDate>
		<dc:creator>Alexis Metaireau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[flac]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[musique]]></category>
		<category><![CDATA[ogg]]></category>

		<guid isPermaLink="false">http://www.notmyidea.org/?p=63</guid>
		<description><![CDATA[J&#8217;ai récemment récupéré plusieurs albums au format flac, et souhaitant pouvoir les lire sur mon baladeur multimédia, j&#8217;ai du les convertir au format mp3 (bouuuuh). 
Rien de bien sorcier, mais les albums en question étaient fournis sous le forme d&#8217;un seul et unique fichier, ainsi que d&#8217;un fichier .cue, contenant les informations de découpage des [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;ai récemment récupéré plusieurs albums au format <em>flac</em>, et souhaitant pouvoir les lire sur mon baladeur multimédia, j&#8217;ai du les convertir au format <em>mp3</em> (bouuuuh). </p>
<p>Rien de bien sorcier, mais les albums en question étaient fournis sous le forme d&#8217;un seul et unique fichier, ainsi que d&#8217;un fichier <em>.cue</em>, contenant les informations de découpage des titres du dit album.</p>
<p>J&#8217;ai donc utilisé <a href='apt://mp3splt'>mp3splt</a>, ainsi que <a href="http://bytemonkey.org/projects/flac2mp3/">flac2mp3</a>. </p>
<p>Téléchargez les différents logiciels, installez les puis placez vous dans le répertoire contenant vos fichiers .flac et tapez:</p>
<div class="codecolorer-container text notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">flac2mp3 . . &amp;&amp; &nbsp;mp3splt -c *.cue *.mp3</div></div>
<p>Et en trois coups de cuillère à pot, le tour est joué!</p>
<p>Il est également possible de procéder de la même manière en obtenant un fichier ogg Vorbis, en utilisant <a href='apt://oggconvert'>oggconvert</a> ou <a href="http://members.fortunecity.com/stateq/flac2ogg.html">flac2ogg</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.notmyidea.org/article/convertir-des-albums-encodes-en-flac-vers-du-mp3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ubuntu &#8211; Impossible de se connecter au réseau wifi</title>
		<link>http://www.notmyidea.org/article/ubuntu-impossible-de-se-connecter-au-reseau-wifi/</link>
		<comments>http://www.notmyidea.org/article/ubuntu-impossible-de-se-connecter-au-reseau-wifi/#comments</comments>
		<pubDate>Tue, 20 May 2008 14:17:10 +0000</pubDate>
		<dc:creator>Alexis Metaireau</dc:creator>
				<category><![CDATA[Humeur]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Notes]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[problème]]></category>
		<category><![CDATA[wifi]]></category>
		<category><![CDATA[wireless networks]]></category>

		<guid isPermaLink="false">http://www.notmyidea.org/?p=62</guid>
		<description><![CDATA[Cette nuit, et sans donner plus d&#8217;explications, mon ordinateur à subitement refusé de se connecter a mon réseau wifi. Lorsque la détection des réseaux voisins, y compris le mien, se passe sans encombres, la connexion échoue systématiquement, nm-applet me demandant sans cesse de (re)saisir la clé de chiffrement.
Il semble s&#8217;agir d&#8217;un problème de configuration, puisque, [...]]]></description>
			<content:encoded><![CDATA[<p>Cette nuit, et sans donner plus d&#8217;explications, mon ordinateur à subitement refusé de se connecter a mon réseau wifi. Lorsque la détection des réseaux voisins, y compris le mien, se passe sans encombres, la connexion échoue systématiquement, <em>nm-applet</em> me demandant sans cesse de (re)saisir la clé de chiffrement.</p>
<p>Il semble s&#8217;agir d&#8217;un problème de configuration, puisque, après création d&#8217;un nouveau compte utilisateur, la connexion en wifi au même point d&#8217;accès ce passe sans encombres. </p>
<p>un</p>
<div class="codecolorer-container text notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">locate wireless | grep ~</div></div>
<p>me retourne une liste des fichiers potentiellement incriminés. Les fichiers de configuration concernant le wifi sont situés dans <em>~/.gconf/system/networking/wireless/networks</em>. </p>
<p>Supprimez les dossiers portant le nom du SSID de votre connexion wifi, et relancez une session: Ils seront regénérés automatiquement à la saisie de votre clé de chiffrement.</p>
<p>Voici la ligne de commande permettant de supprimer l&#8217;intégralité de votre configuration :</p>
<div class="codecolorer-container text notmyidea" style="overflow:auto;white-space:nowrap;width:700px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">rm -Rf ~/.gconf/system/networking/wireless/networks/*</div></div>
<p>Par contre, je n&#8217;ai aucune idée de la provenance du problème &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.notmyidea.org/article/ubuntu-impossible-de-se-connecter-au-reseau-wifi/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
