<?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>Grummfy&#039;s project</title>
	<atom:link href="http://grummfy.be/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://grummfy.be/blog</link>
	<description>Mes projets, mes rêves, mes envies, ...</description>
	<lastBuildDate>Mon, 02 Jan 2012 00:03:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Git fusion de sous répertoire et de l&#8217;historique dans un autre dépôt</title>
		<link>http://grummfy.be/blog/389#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/389#comments</comments>
		<pubDate>Mon, 02 Jan 2012 00:03:47 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[FSB]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[trucs et astuces]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=389</guid>
		<description><![CDATA[Cet article explique comment fusionner des sous répertoire d'un dépôt existant dans un autre en en gardant l'historique.]]></description>
			<content:encoded><![CDATA[<p>Dans le cadre du projet <a title="Fire Soft Board" href="http://grummfy.be/blog/key/fsb">Fire Soft Board</a> il a été décidé de créer un dépôts git dédié aux traductions. Pour ce faire il a fallut reprendre els fichiers mais aussi les placer dans des sous répertoires spécifiques. Voici la démarche effectuée.<br />
<span id="more-389"></span><br />
On désire prendre certaines sous répertoires et les transposer dans le nouveau dépôts.<br />
/Fire-Soft-Board-2/tpl/WhiteSummer/img/fr &#8211;&gt; pack/fr/tpl/WhiteSummer/img/fr<br />
/Fire-Soft-Board-2/lang/fr &#8211;&gt; pack/fr/lang/fr</p>
<ol>
<li>Clone du dépôt principal<br />
<code>git clone https://github.com/FSB/Fire-Soft-Board-2.git<br />
cd Fire-Soft-Board-2</code></li>
<li>Nous avons deux sous répertoires, nous créons donc deux clone local<br />
<code>cd ..<br />
git clone Fire-Soft-Board-2 fsb2-tpl-fr<br />
git clone Fire-Soft-Board-2 fsb2-lang-fr</code></li>
<li>Il faut désormais nettoyer les fichiers mais aussi l&#8217;historique des commits dont nous n&#8217;avons plus besoin. Pour cela, nous allons simplement dire à git de ne garder que les sous répertories dont nous avons besoin.<br />
<code>cd fsb2-lang-fr<br />
git checkout dev<br />
git filter-branch --subdirectory-filter lang/fr HEAD<br />
git gc --prune --aggressive<br />
cd ..<br />
cd fsb2-tpl-fr<br />
git checkout dev<br />
git filter-branch --subdirectory-filter tpl/WhiteSummer/img/fr HEAD<br />
git gc --prune --aggressive<br />
cd ..<br />
</code><br />
git gc permet de nettoyer l&#8217;historique et de compacter l&#8217;index. Cela évite ainsi de potentiel mauvaises surprise dans les logs.</li>
<li>Il faut désormais fusionner ces fichiers ainsi que l&#8217;historique qui va avec dans le dépôt des traductions. Commençons par cloner celui-ci.<code>git clone https://github.com/FSB/FSB2-language-packs.git<br />
cd FSB2-language-packs/</code></li>
<li>Fusionnons les ressources lié au templates<code>git remote add -f tpl ../FSB2-tpl-fr/<br />
git merge -s ours --no-commit tpl/dev<br />
git read-tree --prefix=pack/fr/tpl/WhiteSummer/img/fr -u tpl/dev<br />
git commit -m'Ajout des sources et de l''historique du pack de langue fr des templates'<br />
</code>On effectue un merge mais sans commiter. En mode de merging, on dit que le merge doit s&#8217;effectuer non pas sur la base mais sur un sous répertoire précis.</li>
<li>Ensuite, on fait de même pour la traductions en elle-même.<code>git remote add -f lang ../FSB2-lang-fr/<br />
git merge -s ours --no-commit lang/dev<br />
git read-tree --prefix=pack/fr/lang/fr -u lang/dev<br />
git commit -m'Ajout des sources et de l''historique du pack de langue fr'<br />
</code></li>
<li>On finit par un petit nettoyage<code>git gc<br />
git remote rm lang<br />
git remote rm tpl</code></li>
</ol>
<p>Pour aller plus loin :</p>
<p>http://progit.org/book/fr/ch6-4.html</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/389/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Création de nouveau formulaire facilement avec Zend Form Maker</title>
		<link>http://grummfy.be/blog/381#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/381#comments</comments>
		<pubDate>Sat, 29 Oct 2011 22:29:52 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=381</guid>
		<description><![CDATA[La création de formulaire avec zend framework peut être facilitée grâce à un petit développement : Zend Form Maker. Projet disponible sur github. À la base créer pour des besoins scolaires, sarlak a eu la bonne idée de rendre le dev open source sous licence GPL 3.0. Le but du logiciel est de permettre via [...]]]></description>
			<content:encoded><![CDATA[<p>La création de formulaire avec zend framework peut être facilitée grâce à un petit développement : Zend Form Maker. Projet disponible sur github. À la base créer pour des besoins scolaires, sarlak a eu la bonne idée de rendre le dev open source sous licence GPL 3.0.</p>
<p>Le but du logiciel est de permettre via une interface très simple d&#8217;accès, de créer des formulaires et ensuite de forger une classe PHP, basé sur zend framework afin d&#8217;obtenir un formulaire tout frais moulu. Ultra pratique, et ultra simple, et surtout cela fait gagner un temps de dingue!</p>
<p>Pour l&#8217;installer, il vous faut de quoi faire fonctionner zend framework (celui-ci doit être installé). Sous Unix cela donnera ceci :<br />
<code><br />
git clone https://github.com/sarlak/Zend-Form-Maker.git<br />
ln -s pathToYourZFLibrary<br />
chmod 0777 Zend-Form-Maker/public/resources/xml<br />
chmod 0777 Zend-Form-Maker/public/resources/form_made<br />
</code></p>
<p>Bien entendu, à peu de choses près ceci est adaptable sous MS-Windows</p>
<p>Pour créer votre premier formulaire, il vous suffit de vous rendre sur l&#8217;URL adéquate, aller sur &laquo;&nbsp;form list&nbsp;&raquo; et &laquo;&nbsp;Bazinga!&nbsp;&raquo;. Une <a href="http://demo.zfm.matthieudiblasio.ch/" title="démo" target="_blank">démo</a> existe en ligne!</p>
<p>Une petite capture d&#8217;écran :<br />
<a href="http://grummfy.be/blog/381/capture-zend-form-maker-v1-0-mozilla-firefox" rel="attachment wp-att-383"><img src="http://grummfy.be/blog/wp/wp-content/uploads/2011/10/Capture-Zend-Form-Maker-v1.0-Mozilla-Firefox-300x185.png" alt="" title="Capture-Zend Form Maker v1.0" width="300" height="185" class="aligncenter size-medium wp-image-383" /></a></p>
<p>À noter que j&#8217;ai corrigé un ou deux petits trucs qui me dérangeaient, il y a un bout de temps.</p>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;title=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" id="wpa2a_2"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/381/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git, gitolite et mutualisé OVH</title>
		<link>http://grummfy.be/blog/368#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/368#comments</comments>
		<pubDate>Wed, 10 Aug 2011 21:46:37 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[OVH]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=368</guid>
		<description><![CDATA[Pouvoir utilisé gitolite sur un hébergement mutualisé OVH.]]></description>
			<content:encoded><![CDATA[<p>Hello,<br />
Sur les mutualisés OVH, la version fournie de git est plus qu’out-of-date : version 1.4.4. Ceci signifie impossibilité d&#8217;installé des outils tels que gitolite ou inferno. Ce billet est l&#8217;occasion d&#8217;un guide pour installer gitolite.</p>
<p>Le guide suivant a été rédigé sur un compte OVH pro, donc avec accès un ssh. En utilisant git 1.7.6 et gitolite 2.0.3. L&#8217;ensemble exécuter sur une machine Linux.</p>
<h2>Téléchargement</h2>
<p>La première étape, consiste a récupérer les différentes archives nécessaires, a savoir git et gitolite.</p>
<p>Pour git, il vous suffit de prendre la dernière version http://git-scm.com/download.</p>
<p>Pour gitolite, il suffit d&#8217;utiliser git!</p>
<pre>git clone https://github.com/sitaramc/gitolite.git</pre>
<h2>Préparation de l&#8217;environnement</h2>
<p>Nous allons installer les exécutables de git dans ~/opt/bin. De ce fait ajoutons le path a l&#8217;utilisateur ssh.<br />
Ouvrir ~/.bash_profile et modifier le path. Pour ce faire ajouter, avant le export :</p>
<pre>PATH=$HOME/opt/bin:$PATH</pre>
<h2>Installation de git</h2>
<p>Uploader votre archive dans un dossier (ici ~/opt/src/). En mode console par ssh, donc sur le serveur, ouvrir l&#8217;archive et compiler les sources.</p>
<pre>tar -xvzf git-1.7.6.tar.gz
cd git-1.7.6
./configure --prefix=$HOME/opt --without-tcltk
make
make install</pre>
<p>Une fois compilé, les exécutables seront présents dans ~/opt/bin. Pour vérifier, que tout est bien en place :</p>
<pre>git --version</pre>
<h2>Gitolite</h2>
<p>Il faut se rendre dans le répertoire du clone du repository. <strong>Tout s&#8217;exécute uniquement sur la machine cliente (donc pas chez ovh)</strong>. Si l&#8217;utilisateur est &laquo;&nbsp;toto&nbsp;&raquo;, l&#8217;host &laquo;&nbsp;tata.com&nbsp;&raquo; et le futur administrateur &laquo;&nbsp;moiadmin&nbsp;&raquo;</p>
<pre>./src/gl-easy-install toto tata.com moiadmin</pre>
<p>Il suffit de faire enter. Dans tous les cas (mise à jour du script compris!), le fait de réexecuter la commande permet de rectifier les erreurs éventuelles. À l&#8217;étape de l&#8217;édition du fichier de configuration, il faut modifier la variable $GIT_PATH pour quelle pointe vers le répertoire contenant notre git. Dans notre cas :</p>
<pre>$GIT_PATH = $ENV{HOME} . "/opt/bin/";</pre>
<h2>Configuration de Gitolite</h2>
<p>La configuration de gitolite est simple et s&#8217;exécute avec &#8230; git! En principe, un répertoire reprenant la config a été créé sur votre home dans ~/gitolite-admin, dans le cas contraire, il vous suffit de faire</p>
<pre>git clone gitolite:gitolite-admin.git</pre>
<p>Pour ajouter des clefs ssh, il suffit de les mettre dans le dossier keys. Pour ce qui est de la config, il vous suffit d&#8217;éditer le fichier gitolite.conf et puis de faire</p>
<pre>git add conf/gitolite.conf
git commit -m 'update config'
git push</pre>
<p>Et c&#8217;est tout!</p>
<p>Sources :<br />
<a href="http://forum.ovh.com/showthread.php?t=71543" target="_blank">http://forum.ovh.com/showthread.php?t=71543</a><br />
<a href="http://blog.lyrixx.info/admin-sys/installer-gitolite-sur-une-machine-debian-5/" target="_blank">http://blog.lyrixx.info/admin-sys/installer-gitolite-sur-une-machine-debian-5/</a><br />
<a href="http://sitaramc.github.com/gitolite/doc/gitolite.rc.html" target="_blank" class="broken_link">http://sitaramc.github.com/gitolite/doc/gitolite.rc.html</a><br />
<a href="http://sitaramc.github.com/gitolite/doc/gitolite.conf.html#_groups" target="_blank" class="broken_link">http://sitaramc.github.com/gitolite/doc/gitolite.conf.html#_groups</a></p>
<p>Pour vos interfaces web, trois solutions correctes :<br />
<a href="http://hjemli.net/git/cgit/" target="_blank">CGit</a><br />
<a href="http://viewgit.sourceforge.net/" target="_blank">View Git</a><br />
<a href="http://projects.ceondo.com/p/indefero/" target="_blank">Indefero</a></p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/368/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL : différences entre LEFT JOIN, RIGHT JOIN, etc</title>
		<link>http://grummfy.be/blog/364#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/364#comments</comments>
		<pubDate>Mon, 07 Mar 2011 12:47:21 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Réflexion du jour]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[trucs et astuces]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=364</guid>
		<description><![CDATA[J&#8217;ai toujours eu quelques diffuculté a bien visualisé les différence qu&#8217;il y avait entre left join, right join, join, etc lorsque je fait des requêtes SQL. Aujourd&#8217;hui je suis tombé sur un exemple frappant, et je me suis dit que cela pouvait en aider plus d&#8217;un! Comme une image vaux mieux qu&#8217;un long discours, en [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;ai toujours eu quelques diffuculté a bien visualisé les différence qu&#8217;il y avait entre left join, right join, join, etc lorsque je fait des requêtes SQL. Aujourd&#8217;hui je suis tombé sur un exemple frappant, et je me suis dit que cela pouvait en aider plus d&#8217;un! Comme une image vaux mieux qu&#8217;un long discours, en voici l&#8217;essence.</p>
<p>L&#8217;exemple suivant se base sur une base de donnée mysql :<br />
<code lang="SQL"><br />
CREATE TABLE IF NOT EXISTS `acl_roles` (<br />
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,<br />
`name` varchar(30) CHARACTER SET utf8 NOT NULL,<br />
`build_on` int(11) unsigned DEFAULT NULL,<br />
PRIMARY KEY (`id`),<br />
KEY `build_on` (`build_on`)<br />
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin;</p>
<p>INSERT INTO `acl_roles` (`id`, `name`, `build_on`) VALUES<br />
(1, 'guest', NULL),<br />
(2, 'normal', 1),<br />
(3, 'modo', 2),<br />
(4, 'admin', 3);</p>
<p>ALTER TABLE `acl_roles`  ADD CONSTRAINT FOREIGN KEY (`build_on`) REFERENCES `acl_roles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;<br />
</code></p>
<p>Nous avons donc une table avec des clefs de référence pour marquer les dépendance entre les roles. En images cela donne ceci :</p>
<table boder="1">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>build_on</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>guest</td>
<td>NULL</td>
</tr>
<tr>
<td>2</td>
<td>normal</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>modo</td>
<td>2</td>
</tr>
<tr>
<td>4</td>
<td>admin</td>
<td>3</td>
</tr>
</tbody>
</table>
<p>Maintenant regardons le résultats de divers SELECT, le résultat parle de lui-même.</p>
<p>SELECT ar.*, arp.name AS parent_name FROM acl_roles ar, acl_roles arp WHERE arp.id = ar.build_on</p>
<table boder="1">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>build_on</th>
<th>parent_name</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">2</td>
<td>normal</td>
<td align="right">1</td>
<td>guest</td>
</tr>
<tr>
<td align="right">3</td>
<td>modo</td>
<td align="right">2</td>
<td>normal</td>
</tr>
<tr>
<td align="right">4</td>
<td>admin</td>
<td align="right">3</td>
<td>modo</td>
</tr>
</tbody>
</table>
<p>SELECT ar.*, arp.name AS parent_name FROM acl_roles ar LEFT JOIN acl_roles arp ON arp.id = ar.build_on</p>
<table boder="1">
<thead>
<tr>
<th>id</th>
<th> name</th>
<th> build_on</th>
<th> parent_name</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">1</td>
<td>guest</td>
<td align="right"><em>NULL</em></td>
<td><em>NULL</em></td>
</tr>
<tr>
<td align="right">2</td>
<td>normal</td>
<td align="right">1</td>
<td>guest</td>
</tr>
<tr>
<td align="right">3</td>
<td>modo</td>
<td align="right">2</td>
<td>normal</td>
</tr>
<tr>
<td align="right">4</td>
<td>admin</td>
<td align="right">3</td>
<td>modo</td>
</tr>
</tbody>
</table>
<p>SELECT ar.*, arp.name AS parent_name FROM acl_roles ar JOIN acl_roles arp ON arp.id = ar.build_on</p>
<table boder="1">
<thead>
<tr>
<th>id</th>
<th> name</th>
<th> build_on</th>
<th> parent_name</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">2</td>
<td>normal</td>
<td align="right">1</td>
<td>guest</td>
</tr>
<tr>
<td align="right">3</td>
<td>modo</td>
<td align="right">2</td>
<td>normal</td>
</tr>
<tr>
<td align="right">4</td>
<td>admin</td>
<td align="right">3</td>
<td>modo</td>
</tr>
</tbody>
</table>
<p>SELECT ar.*, arp.name AS parent_name FROM acl_roles ar RIGHT JOIN acl_roles arp ON arp.id = ar.build_on</p>
<table boder="1">
<thead>
<tr>
<th>id</th>
<th> name</th>
<th> build_on</th>
<th> parent_name</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">2</td>
<td>normal</td>
<td align="right">1</td>
<td>guest</td>
</tr>
<tr>
<td align="right">3</td>
<td>modo</td>
<td align="right">2</td>
<td>normal</td>
</tr>
<tr>
<td align="right">4</td>
<td>admin</td>
<td align="right">3</td>
<td>modo</td>
</tr>
<tr>
<td align="right"><em>NULL</em></td>
<td><em>NULL</em></td>
<td align="right"><em>NULL</em></td>
<td>admin</td>
</tr>
</tbody>
</table>
<p>J&#8217;espère que l&#8217;exemple servira a certain et que cela en aidera plus d&#8217;un!</p>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F364&amp;linkname=SQL%20%3A%20diff%C3%A9rences%20entre%20LEFT%20JOIN%2C%20RIGHT%20JOIN%2C%20etc" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F364&amp;linkname=SQL%20%3A%20diff%C3%A9rences%20entre%20LEFT%20JOIN%2C%20RIGHT%20JOIN%2C%20etc" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F364&amp;linkname=SQL%20%3A%20diff%C3%A9rences%20entre%20LEFT%20JOIN%2C%20RIGHT%20JOIN%2C%20etc" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F364&amp;linkname=SQL%20%3A%20diff%C3%A9rences%20entre%20LEFT%20JOIN%2C%20RIGHT%20JOIN%2C%20etc" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F364&amp;linkname=SQL%20%3A%20diff%C3%A9rences%20entre%20LEFT%20JOIN%2C%20RIGHT%20JOIN%2C%20etc" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F364&amp;linkname=SQL%20%3A%20diff%C3%A9rences%20entre%20LEFT%20JOIN%2C%20RIGHT%20JOIN%2C%20etc" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F364&amp;title=SQL%20%3A%20diff%C3%A9rences%20entre%20LEFT%20JOIN%2C%20RIGHT%20JOIN%2C%20etc" id="wpa2a_4"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/364/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZF : ACL et ressources multiple</title>
		<link>http://grummfy.be/blog/360#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/360#comments</comments>
		<pubDate>Wed, 13 Oct 2010 21:19:21 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=360</guid>
		<description><![CDATA[Utiliser les ACL dans Zend Framework en ajoutant le support de ressource multiple via '*'.]]></description>
			<content:encoded><![CDATA[<p>Lorsque l&#8217;on utilise des ACL dans Zend Framework, une chose assez embêtante est de devoir tout mettre en place<sup class='footnote'><a href='#fn-360-1' id='fnref-360-1'>1</a></sup>. Pour ma part, j&#8217;ai par facilité voulu ajouté le support de ressource multiple.</p>
<p>Avant de commencer, il convient de contextualisé les choses, les ACL de ZF pouvant être utilisé de bien des manière.</p>
<p>Dans le cas qui nous intéresse, j&#8217;ai simplement défini ceci :</p>
<ul>
<li>les ressources<sup class='footnote'><a href='#fn-360-2' id='fnref-360-2'>2</a></sup> = module.controller</li>
<li>les privilèges<sup class='footnote'><a href='#fn-360-3' id='fnref-360-3'>3</a></sup> = action</li>
</ul>
<p>Ce que je voulait c&#8217;est pouvoir définir une ressource pour tous les contrôleurs. La syntaxe évidente qu&#8217;il m&#8217;est venu est la suivante : module.*</p>
<p>Dans ma classe qui étend Zend_ACL j&#8217;ai simplement fait ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isAllowed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$privilege</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span>
    		<span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">isAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #339933;">,</span> <span style="color: #000088;">$privilege</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #000088;">$resources</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getResourcesPossibility<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resources</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span>
    	<span style="color: #009900;">&#123;</span>
    		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>has<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">isAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #339933;">,</span> <span style="color: #000088;">$privilege</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    		<span style="color: #009900;">&#123;</span>
    			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    		<span style="color: #009900;">&#125;</span>
    	<span style="color: #009900;">&#125;</span>
    	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getResourcesPossibility<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span>
    	<span style="color: #009900;">&#123;</span>
    		<span style="color: #000088;">$resources</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    		<span style="color: #000088;">$cptRessources</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resources</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cptRessources</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
    		<span style="color: #009900;">&#123;</span>
    			<span style="color: #000088;">$resources</span><span style="color: #009900;">&#91;</span> <span style="color: #000088;">$cptRessources</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'*'</span><span style="color: #339933;">;</span>
    		<span style="color: #009900;">&#125;</span>
    		<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resources</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
    	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ceci peut bien entendu être enrichi mais permet au moins de profiter de l&#8217;utilisation des ACL dans le menu et sur des aides de vue qui serait éventuellement définie comme expliqué dans la plupart des tutoriaux.</p>
<p>Pour en savoir plus sur les ACL et Zend Framework, je vous renvoi a un très bon <a href="http://julien-pauli.developpez.com/tutoriels/zend-framework/atelier/aclmvc/" target="_blank">article</a>.</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-360-1'>surtout si on utilise l&#8217;aide de vue pour généré un menu (Zend_navigation) <span class='footnotereverse'><a href='#fnref-360-1'>&#8617;</a></span></li>
<li id='fn-360-2'>resource <span class='footnotereverse'><a href='#fnref-360-2'>&#8617;</a></span></li>
<li id='fn-360-3'>privilege <span class='footnotereverse'><a href='#fnref-360-3'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/360/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZF : module et autoloader</title>
		<link>http://grummfy.be/blog/343#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/343#comments</comments>
		<pubDate>Sun, 22 Aug 2010 22:00:55 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=343</guid>
		<description><![CDATA[Avec Zend Framework, lorsque l&#8217;on travail un projet conséquent il devient vite utile de travailler avec le mécanisme des modules. Celui-ci permet d&#8217;étendre pas mal de chose et surtout une séparation poussée en &#8230; module. Le problème de ce mécanisme1 est qu&#8217;il faut définir le chemin pour le chargement automatique à l&#8217;aide de ceci : [...]]]></description>
			<content:encoded><![CDATA[<p>Avec Zend Framework, lorsque l&#8217;on travail un projet conséquent il devient vite utile de travailler avec le mécanisme des <a href="http://framework.zend.com/manual/fr/zend.controller.modular.html" target="_blank">modules</a>. Celui-ci permet d&#8217;étendre pas mal de chose et surtout une séparation poussée en &#8230; module.</p>
<p>Le problème de ce mécanisme<sup class='footnote'><a href='#fn-343-1' id='fnref-343-1'>1</a></sup> est qu&#8217;il faut définir le chemin pour le chargement automatique à l&#8217;aide de ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoloader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application_Module_Autoloader<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'namespace'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'SuperModule'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'basePath'</span>  <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'path to super module'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Je vous propose donc de faire une petite amélioration afin que ce chargement soit fait automatiquement.</p>
<p>Avant tout, dans votre configuration (ici en .ini) vous devez au moins avoir ceci de présent :</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">resources.frontController.moduleDirectory <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> APPLICATION_PATH </span><span style="color: #933;">&quot;/modules&quot;</span>
resources.modules <span style="color: #000066; font-weight:bold;">=</span></pre></div></div>

<p>Ensuite, à la base de chaque dossier module créer un fichier Bootstrap.php<sup class='footnote'><a href='#fn-343-2' id='fnref-343-2'>2</a></sup> :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #000000; font-weight: bold;">class</span> SuperModule_Bootstrap <span style="color: #000000; font-weight: bold;">extends</span> Grummfy_Bootstrap<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>Et pour finir créer le fichier<sup class='footnote'><a href='#fn-343-3' id='fnref-343-3'>3</a></sup> library/Grummfy/Bootstrap.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
&nbsp;
abstract <span style="color: #000000; font-weight: bold;">class</span> Grummfy_Bootstrap <span style="color: #000000; font-weight: bold;">extends</span> Zend_Application_Bootstrap_Bootstrap
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initAutoload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$className</span> <span style="color: #339933;">=</span> <span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$zf_namespace</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$reflector</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionClass<span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$autoloader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application_Module_Autoloader<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'namespace'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$zf_namespace</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'basePath'</span>  <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$reflector</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getFileName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$autoloader</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-343-1'>sauf si j&#8217;ai loupé un truc&#8230; <span class='footnotereverse'><a href='#fnref-343-1'>&#8617;</a></span></li>
<li id='fn-343-2'>ne pas oublier de changer le nom du module &#8230; <span class='footnotereverse'><a href='#fnref-343-2'>&#8617;</a></span></li>
<li id='fn-343-3'>n&#8217;oubliez pas de déclarer le &laquo;&nbsp;namespace&nbsp;&raquo; Grummfy ou bien d&#8217;inclure le fichier <span class='footnotereverse'><a href='#fnref-343-3'>&#8617;</a></span></li>
</ol>
</div>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;title=ZF%20%3A%20module%20et%20autoloader" id="wpa2a_6"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/343/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZF : génération automatique du fichier de navigation et ACL</title>
		<link>http://grummfy.be/blog/333#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/333#comments</comments>
		<pubDate>Mon, 16 Aug 2010 20:47:14 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[délire]]></category>
		<category><![CDATA[jouons]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=333</guid>
		<description><![CDATA[Lors de l&#8217;utilisation du mécanisme d&#8217;ACL et de génération de menu dans Zend Framework, il est intéressant de limiter l&#8217;affichage de ce menu en utilisant les ressources et privilèges associer. Pour ma part, j&#8217;utilise un fichier XML pour construire mon menu, mon sitemap, &#8230; 1. Et comme beaucoup je génère mon projet ZF à l&#8217;aide [...]]]></description>
			<content:encoded><![CDATA[<p>Lors de l&#8217;utilisation du mécanisme d&#8217;ACL et de génération de menu dans Zend Framework, il est intéressant de limiter l&#8217;affichage de ce menu en utilisant les ressources et privilèges associer.</p>
<p>Pour ma part, j&#8217;utilise un fichier XML pour construire mon menu, mon sitemap, &#8230; <sup class='footnote'><a href='#fn-333-1' id='fnref-333-1'>1</a></sup>. Et comme beaucoup je génère mon projet ZF à l&#8217;aide de Zend_Tool. Je trouvais donc dommage de devoir réécrire pratiquement la même chose que ce que j&#8217;avais déclaré dans Zend_Tool pour reconstruire mon menu. J&#8217;ai donc décidé de <em>rapidement</em> écrire un petit script qui reprendrait le fichier XML du projet et le transformerait en menu &#8230;</p>
<p>À noter que le script devrait certainement être amélioré, mais que cela permet un gain de temps considérable &#8230;</p>
<p><a href="http://grummfy.com/download/PlusScript/zfProject2Navigation.phps" target="_blank">Téléchargement</a></p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-333-1'>Comme expliquer dans le manuel http://framework.zend.com/manual/fr/zend.navigation.html <span class='footnotereverse'><a href='#fnref-333-1'>&#8617;</a></span></li>
</ol>
</div>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;title=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" id="wpa2a_8"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/333/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Réécriture d’URL, alias et plusieurs développeurs sur Apache</title>
		<link>http://grummfy.be/blog/321#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/321#comments</comments>
		<pubDate>Thu, 12 Aug 2010 21:07:55 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[url rewriting]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=321</guid>
		<description><![CDATA[Une solution à la problématique des réécritures d'url sans rewriteBase tout en étant utilisable par plusieurs développeurs]]></description>
			<content:encoded><![CDATA[<p>Lorsque l&#8217;on travaille à plusieurs sur un projet, c&#8217;est toujours intéressant. Malheureusement, cela peut aussi entrainer divers problèmes. Je vais tenter de vous expliquer un ﻿﻿obstacle qui peut vite devenir très chi*nt&#8230;</p>
<p>Pour présenter cette problématique, je vais prendre exemple sur ce que je développe actuellement. Le site en cours de création se base sur zend framework et nécessite une réécriture d&#8217;URL. Il faut savoir qu&#8217;Apache utilise le chemin physique<sup class='footnote'><a href='#fn-321-1' id='fnref-321-1'>1</a></sup> comme base pour calculer le chemin vers le fichier réécrit sauf si on lui précise une directive RewriteBase différente. Le problème survient à cet endroit, plusieurs développeurs entrainent plusieurs machines et donc plusieurs configurations différentes!</p>
<p>La solution de base est que chaque personne utilisant un alias Apache définit un RewriteBase. Cependant, cela veut dire qu’a chaque nouvelle version du fichier .htaccess il faut redéfinir celui-ci.</p>
<p>La réponse la plus simple consiste à utiliser un RewriteCond sur l&#8217;hostname du serveur et bien entendu à l&#8217;utiliser lors de l&#8217;accès aux tests locaux ou non &#8230;</p>
<p>Exemple de configuration :</p>
<ul>
<li> nom du serveur : grummfy</li>
<li>URL appelée : http://grummfy/serveur/dev/projet/example.com/&#8230; (Si vous utilise http://localhost/ la directive HTTP_HOST vaudra localhost)</li>
<li>ALIAS : /serveur/ =&gt; /media/data/serveur/</li>
</ul>
<p>Le fichier .htacccess contiendra ceci :<br />
<code>SetEnv APPLICATION_ENV development<br />
php_value session.auto_start 0<br />
php_flag magic_quotes_gpc off<br />
RewriteEngine On<br />
RewriteCond %{REQUEST_FILENAME} -s [OR]<br />
RewriteCond %{REQUEST_FILENAME} -l [OR]<br />
RewriteCond %{REQUEST_FILENAME} -d<br />
RewriteRule ^.*$ - [NC,L]<br />
RewriteCond %{HTTP_HOST} grummfy<br />
RewriteRule ^.*$ /serveur/dev/projet/example.com/index.php [NC,L]<br />
RewriteRule ^.*$ index.php [NC,L]</code></p>
<p>Le fait d&#8217;utiliser le rewrite flag &laquo;&nbsp;L&nbsp;&raquo; permet de sortir de la réécriture d&#8217;URL. Si le hostname du serveur n&#8217;est pas grummfy il appliquera la règle par défaut, à savoir tenter de trouver index.php dans /media/data/serveur/dev/projet/example.com/ comme si on avait effectuer un appel depuis http://media/data/serveur/dev/projet/example.com/</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-321-1'>physical-directory-path <span class='footnotereverse'><a href='#fnref-321-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/321/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android : Tri d&#8217;une ListView tout en gardant les ids</title>
		<link>http://grummfy.be/blog/312#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/312#comments</comments>
		<pubDate>Sat, 19 Jun 2010 22:50:19 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[trucs et astuces]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=312</guid>
		<description><![CDATA[Menu ListView dans une ListActivity, trié selon un ordre alphabétique. Récupération de l'élément cliqué...]]></description>
			<content:encoded><![CDATA[<p>Durant le développement du projet <a title="Projet B-Box" href="http://code.google.com/p/b-box/" target="_blank">b-box</a> j&#8217;ai rencontré un problème avec mon menu. Ce menu est présent sous forme de ListActivity (comprenant une ListView), était trié selon un ordre alphabétique qui est susceptible de changer puisque l&#8217;application peut-être traduite.</p>
<p>Au début, j&#8217;ai essayé diverses méthodes, mais les id de position étant perdus&#8230; pas moyen de savoir à quoi correspond quoi.</p>
<p>J&#8217;ai donc du trouver <a href="http://forum.frandroid.com/forum/viewtopic.php?id=15727" target="_blank" class="broken_link">une solution</a>, solution que je vous présente.</p>
<h2>But</h2>
<p>Le but est de créer un menu sous forme de liste (ListView) dont chaque élément est cliquable et permet de récupérer l&#8217;id du clic. Cet id servant à lancer une autre Activity, par exemple.</p>
<h2>Exemple</h2>
<p>Tout d&#8217;abord la classe Menu :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.android.bbox</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Comparator</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> <span style="color: #003399;">Menu</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> label<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Menu</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id, <span style="color: #003399;">String</span> label<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">label</span> <span style="color: #339933;">=</span> label<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getLabel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">label</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Menu</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> factory<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> menus<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Menu</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> menu <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Menu</span><span style="color: #009900;">&#91;</span>menus.<span style="color: #006633;">length</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> menus.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			menu<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Menu</span><span style="color: #009900;">&#40;</span>i, menus<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> menu<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Comparator</span> getComparator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Comparator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			@Override
			<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> compare<span style="color: #009900;">&#40;</span><span style="color: #003399;">Menu</span> m1, <span style="color: #003399;">Menu</span> m2<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">return</span> m1.<span style="color: #006633;">getLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>m2.<span style="color: #006633;">getLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Et la classe de l&#8217;activité :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// ...</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//...</span>
		<span style="color: #003399;">Menu</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> m <span style="color: #339933;">=</span> <span style="color: #003399;">Menu</span>.<span style="color: #006633;">factory</span><span style="color: #009900;">&#40;</span>getResources<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStringArray</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">array</span>.<span style="color: #006633;">main_list_array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//récupération d'un tableau de string et création d'un tableau de Menu</span>
		ArrayAdapter adapter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayAdapter<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, android.<span style="color: #006633;">R</span>.<span style="color: #006633;">layout</span>.<span style="color: #006633;">simple_list_item_1</span>, m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//création de l'adaptateur permettant l'affichage</span>
		adapter.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Menu</span>.<span style="color: #006633;">getComparator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//tri du menu</span>
		<span style="color: #003399;">ListView</span> myList <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">ListView</span><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>android.<span style="color: #006633;">R</span>.<span style="color: #006633;">id</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		myList.<span style="color: #006633;">setAdapter</span><span style="color: #009900;">&#40;</span>adapter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//ajotu du menu à la ListView</span>
		myList.<span style="color: #006633;">setOnItemClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//...</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onItemClick<span style="color: #009900;">&#40;</span>AdapterView parent, <span style="color: #003399;">View</span> view, <span style="color: #000066; font-weight: bold;">int</span> position, <span style="color: #000066; font-weight: bold;">long</span> id<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; | &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>parent.<span style="color: #006633;">getItemAtPosition</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; | &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>parent.<span style="color: #006633;">getItemAtPosition</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; | &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Menu</span><span style="color: #009900;">&#41;</span>parent.<span style="color: #006633;">getItemAtPosition</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; | &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//...</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// ...</span></pre></div></div>

<p><strong>Remarque</strong> : la méthode toString permet l&#8217;affichage de l&#8217;élément dans la liste.</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/312/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebHook Google Code &#8211; recevoir un mail à chaque commit</title>
		<link>http://grummfy.be/blog/310#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/310#comments</comments>
		<pubDate>Fri, 18 Jun 2010 23:58:59 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=310</guid>
		<description><![CDATA[Google code et webhook : envoyer un email a chaque commit]]></description>
			<content:encoded><![CDATA[<p>Dans Google code il y a la possibilité d&#8217;utiliser un gestionnaire de version tel que subversion (svn) ou mercurial (hg). C&#8217;est bien pratique, mais malheureusement, de base, rien n&#8217;est prévu pour prévenir (excepté par flux RSS) les gens de ces mises à jour. Cependant, Google code permet d&#8217;utiliser un webhook en post commit.</p>
<h2>Qu&#8217;est-ce qu&#8217;un webhook?</h2>
<p>Un webhook c&#8217;est un &laquo;&nbsp;crochet web&nbsp;&raquo;, c&#8217;est-à-dire une URL a appelée après (avant ou pendant) une action X. Dans notre cas, après chaque commit une URL est appelée.</p>
<h2>Utilisation</h2>
<p>Voici un exemple de code que j&#8217;utilise pour plusieurs de mes projets :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// project name</span>
<span style="color: #000088;">$projects</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mon-super-projet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// google code webhook key</span>
<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'b-box'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Top-Secret_key_fourni_par_google-dans-l-adminsitration'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//user agent from google code</span>
<span style="color: #000088;">$useragent</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Google Code Project Hosting (+http://code.google.com/p/support/wiki/PostCommitWebHooks)'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//email of all owner (eg. project chief)</span>
<span style="color: #000088;">$owners</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'vous@example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//email of all team members except owners</span>
<span style="color: #000088;">$users</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'toi@example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//sender of email</span>
<span style="color: #000088;">$sender</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'WebHook mailer&lt;webmaster@exemple.com&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//----------------------------------------------------------------------</span>
<span style="color: #000088;">$project</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'p'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'p'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$revision</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:-</span><span style="color: #cc66cc;">99</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'php://input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$digest</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//----------------------------------------------------------------------</span>
<span style="color: #009933; font-style: italic;">/**
 * Send a mail
 * @param string $from email of the sender : sample@example.com or &quot;name&quot;&lt;sample@example.com&gt;;
 * @param array $to [a] =&gt; list of email [cc], [bcc] (hidden), ...
 * @param string $subject
 * @param string $body
 * @return bool true if success
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> mailer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$from</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span> <span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'From: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$from</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bcc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bcc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Bcc: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bcc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Cc: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'MIME-Version: 1.0'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Content-Type: text/plain; charset=&quot;UTF-8&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Content-Transfer-Encoding: 8bit'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'X-Mailer: PHP/'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">phpversion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'[webhook]'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> failed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$test_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$sender</span><span style="color: #339933;">,</span> <span style="color: #000088;">$owners</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$msg</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>--<span style="color: #000099; font-weight: bold;">\n</span>WebHook mail from the Google code project&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	mailer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sender</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bcc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$owners</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'failed test #'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$test_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'KO'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> get_ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_X_FORWARDED_FOR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_X_FORWARDED_FOR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_CLIENT_IP'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_CLIENT_IP'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//----------------------------------------------------------------------</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$useragent</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// failed 1</span>
	failed<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'User agent is bad : '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>From : &quot;</span> <span style="color: #339933;">.</span> get_ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$project</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$project</span><span style="color: #339933;">,</span> <span style="color: #000088;">$projects</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// failed 2</span>
	failed<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'No project set : '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$project</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>From : &quot;</span> <span style="color: #339933;">.</span> get_ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$hmac</span> <span style="color: #339933;">=</span> <span style="color: #990000;">hash_hmac</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'md5'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keys</span><span style="color: #009900;">&#91;</span> <span style="color: #000088;">$project</span> <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$digest</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$digest</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$hmac</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// failed 3</span>
		failed<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Bad digest : '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$digest</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' vs '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$hmac</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>From : &quot;</span> <span style="color: #339933;">.</span> get_ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revision_count'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revisions'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// failed 4</span>
		failed<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Bad count : '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revisions'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' vs '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revision_count'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>From : &quot;</span> <span style="color: #339933;">.</span> get_ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revisions'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$_revision</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Revision : '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revision'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' from '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'author'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' at '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d H:i'</span><span style="color: #339933;">,</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'timestamp'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Added : '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'added'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Modified : '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'modified'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Removed : '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'removed'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//			$mail_body .= 'URL : ' . &quot;\t\t&quot; . htmlentities($_revision['url']) . &quot;\n\n&quot;;</span>
			<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Message : '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//			$_revision['path_count'];</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>--<span style="color: #000099; font-weight: bold;">\n</span>WebHook mail from the Google code project : &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$project</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>http://code.google.com/p/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$project</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		mailer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sender</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bcc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$owners</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$users</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'['</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$project</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">']New revision #'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$revision</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mail_body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'OK'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

</p>
<p>Plus d&#8217;info : <a href="http://code.google.com/p/support/wiki/PostCommitWebHooks">PostCommitWebHooks</a></p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/310/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Espace de nom PHP et chargement automatique</title>
		<link>http://grummfy.be/blog/285#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/285#comments</comments>
		<pubDate>Mon, 07 Jun 2010 08:42:44 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=285</guid>
		<description><![CDATA[PHP 5.3 ajoute une notion intéressante : les espaces de nom. Voyons voir comment créer un chargeur automatique (ou autoloader) comprenant ceux-ci.]]></description>
			<content:encoded><![CDATA[<p><a href="./zend-framework#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">PHP</a> 5.3 ajoute une notion intéressante : les espaces de nom (ou namespace en anglais). Les espaces de nom permettent de séparer différents &#8230; &laquo;&nbsp;<em>espace</em>&laquo;&nbsp;, permettant ainsi d&#8217;avoir deux classe portant le même nom. Idéal pour l&#8217;utilisation de framework mais aussi de &laquo;&nbsp;l&#8217;isolation&nbsp;&raquo; de certains composants. Voyons voir comment créer un chargeur automatique (ou autoloader) comprenant les espaces de nom.</p>
<p>Si vous êtes sous Ms Windows, aucun problème un simple <em>spl_autoload_register();</em> suffit. Malheureusement, sous *nix un <a href="http://bugs.php.net/bug.php?id=51991" target="_blank">bug existe</a> il faudra donc implémenté une solution maison.</p>
<h2>Le code</h2>
<p>Ce code provient du &laquo;&nbsp;<a href="http://groups.google.com/group/php-standards/web/psr-0-final-proposal" class="broken_link">PHP  Standards Working Group</a>&nbsp;&raquo; :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$className</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ltrim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'\\'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$fileName</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$namespace</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lastNsPos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strripos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'\\'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$namespace</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lastNsPos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$className</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lastNsPos</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$fileName</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\\'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span><span style="color: #339933;">,</span> <span style="color: #000088;">$namespace</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$fileName</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span><span style="color: #339933;">,</span> <span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">require</span> <span style="color: #000088;">$fileName</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>Pour l&#8217;utiliser, il faut définir deux choses :</p>
<ol>
<li>Ne pas oublier de modifier l&#8217;include path si nécessaire.</li>
<li>Ajouter cette fonction au chargeur de classes présent.</li>
</ol>
<h2>L&#8217;exemple</h2>
<p>Voici un exemple un peu plus complet.<br />
index.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/lib/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//on ajoute le dossier lib dans l'include path</span>
<span style="color: #990000;">spl_autoload_register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//sur windows ceci devrait suffire .</span>
<span style="color: #666666; font-style: italic;">//le code pour les autres</span>
<span style="color: #666666; font-style: italic;">//----------------------------------------------------------</span>
<span style="color: #000000; font-weight: bold;">function</span> autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$className</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ltrim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'\\'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$fileName</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$namespace</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lastNsPos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strripos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'\\'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$namespace</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lastNsPos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$className</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lastNsPos</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$fileName</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\\'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span><span style="color: #339933;">,</span> <span style="color: #000088;">$namespace</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$fileName</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span><span style="color: #339933;">,</span> <span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">require</span> <span style="color: #000088;">$fileName</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">spl_autoload_register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'autoload'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//----------------------------------------------------------</span>
<span style="color: #666666; font-style: italic;">//fin du code de fix</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> grummfy\test\Test<span style="color: #339933;">;</span>
Test<span style="color: #339933;">::</span><span style="color: #004000;">sayHello</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
\grummfy\std\Test<span style="color: #339933;">::</span><span style="color: #004000;">sayHello</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>./lib/grummfy/test/Test.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">namespace</span> grummfy\test<span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//pour rappel ceci doit-être la première instruction php (et on ne doit pas avoir de HTML avant)</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Je suis inclus ('</span> <span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">__FILE__</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">')!'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">class</span> Test
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Bonjour depuis '</span> <span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>./lib/grummfy/std/Test.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">namespace</span> grummfy\std<span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Je suis inclus ('</span> <span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">__FILE__</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">')!'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">class</span> Test
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Bonjour depuis '</span> <span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>Le résultat devrait être :<br />
<code><br />
Je suis inclus (/.../lib/grummfy/test/Test.php)!<br />
Bonjour depuis grummfy\test\Test<br />
Je suis inclus (/.../lib/grummfy/std/Test.php)!<br />
Bonjour depuis grummfy\std\Test<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/285/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Réécriture d&#8217;url et erreur interne à Apache</title>
		<link>http://grummfy.be/blog/289#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/289#comments</comments>
		<pubDate>Fri, 04 Jun 2010 13:15:29 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[deboguage]]></category>
		<category><![CDATA[serveur]]></category>
		<category><![CDATA[url rewriting]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=289</guid>
		<description><![CDATA[Il arrive que lors de l'écriture d'un nombre complexe de règle de réécriture d'URL, des erreurs se produisent. Passons au débogage de celles-ci.]]></description>
			<content:encoded><![CDATA[<p>Il arrive que lors de l&#8217;écriture d&#8217;un nombre complexe de règle de réécriture d&#8217;URL (URL rewriting), des erreurs se produisent sans pour autant être compréhensibles. Je vous propose donc de regarder comment déboguer cela à travers un exemple pratique.</p>
<h2>Exemple</h2>
<p>Prenons une règles qui vérifierait que seul certains type de caractère sont autorisés.<br />
La réécriture quant à elle se fait sur toute URL.<br />
Ajoutons un document 403 personnalisé<br />
<code>RewriteEngine on<br />
#<br />
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/ [NC]<br />
RewriteRule .* - [F,NS,L]<br />
#<br />
#if not a dir or a file<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
#<br />
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]<br />
ErrorDocument 403 /erreur/403<br />
</code><br />
Testons l&#8217;URL http://localhost/test:s et on obtient un beau :</p>
<blockquote><p>Forbidden</p>
<p>You don&#8217;t have permission to access /test:s on this server.</p>
<p>Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.</p></blockquote>
<p>Les logs d&#8217;erreurs d&#8217;Apache vous diront certainement quelque chose du genre :</p>
<blockquote><p>[error] [client 127.0.0.1] Request exceeded the limit of 10 internal  redirects due to probable configuration error. Use  &#8216;LimitInternalRecursion&#8217; to increase the limit if necessary. Use  &#8216;LogLevel debug&#8217; to get a backtrace.</p></blockquote>
<h2>Passage en mode debug de Apache</h2>
<p>Modifions la règle de log du site courant (soit dans /etc/apache2/sites-available/default soit dans /etc/apache2/apache.conf ou l&#8217;équivalent suivant votre configuration ou OS) et modifions la directive <em>&laquo;&nbsp;LogLevel warn&nbsp;&raquo;</em> en <em>&laquo;&nbsp;LogLevel debug&nbsp;&raquo;</em>. Ceci ne change rien dans notre cas, mais parfois cela s&#8217;avère utile&#8230;</p>
<p>Ajoutons ensuite les log<sup class='footnote'><a href='#fn-289-1' id='fnref-289-1'>1</a></sup> de réécriture d&#8217;url (moi je l&#8217;ai ajouter dans /etc/apache2/mods-available/rewrite.conf puis j&#8217;ai fait un a2enmod rewrite (car le fichier .conf n&#8217;existait pas) et enfin j&#8217;ai relancer Apache) :<br />
<code>&lt;IfModule mod_rewrite.c&gt;<br />
RewriteLog "/var/log/apache2/rewrite.log"<br />
RewriteLogLevel 9<br />
&lt;/IfModule&gt;</code></p>
<p>Maintenant si vous aller voir dans error.log vous aurez :</p>
<blockquote><p>[error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use &#8216;LimitInternalRecursion&#8217; to increase the limit if necessary. Use &#8216;LogLevel debug&#8217; to get a backtrace.<br />
[debug] core.c(3063): [client 127.0.0.1] r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/test:s</p></blockquote>
<p>Donc on voit que la redirection s&#8217;effectue correctement mais qu&#8217;il &laquo;&nbsp;<em>n&#8217;accroche</em>&nbsp;&raquo; pas. Regardons donc les logs de la réécriture d&#8217;URL (rewrite.log) :</p>
<blockquote><p>/initial] (3) [perdir /.../] strip per-dir prefix: /&#8230;/test:s -&gt; test:s<br />
/initial] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;test:s&#8217;<br />
/initial] (4) [perdir /.../] RewriteCond: input=&nbsp;&raquo; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial] (3) [perdir /.../] strip per-dir prefix: /&#8230;/test:s -&gt; test:s<br />
/initial] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;test:s&#8217;<br />
/initial] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/test:s<br />
/initial/redir#1] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#1] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#1] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#1] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#1] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#1] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#1] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#1] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#1] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#2] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#2] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#2] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#2] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#2] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#2] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#2] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#2] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#2] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#3] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#3] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#3] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#3] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#3] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#3] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#3] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#3] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#3] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#4] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#4] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#4] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#4] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#4] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#4] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#4] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#4] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#4] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#5] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#5] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#5] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#5] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#5] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#5] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#5] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#5] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#5] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#6] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#6] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#6] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#6] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#6] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#6] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#6] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#6] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#6] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#7] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#7] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#7] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#7] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#7] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#7] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#7] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#7] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#7] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#8] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#8] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#8] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#8] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#8] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#8] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#8] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#8] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#8] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#9] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#9] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#9] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#9] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#9] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#9] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#9] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#9] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#9] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#10] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#10] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#10] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#10] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#10] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#10] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#10] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#10] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#10] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur</p></blockquote>
<p>En gros, nous avions une boucle de redirection. Pour l&#8217;éviter ajoutons,d ans le .htaccess, une condition qui dira de ne pas rentrer dans le bloc, s&#8217;il y a une erreur 403 :<br />
<code>RewriteEngine on<br />
#<br />
RewriteCond %{ENV:REDIRECT_STATUS} !403<br />
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/ [NC]<br />
RewriteRule .* - [F,NS,L]<br />
#<br />
#if not a dir or a file<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
#<br />
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]<br />
ErrorDocument 403 /erreur/403<br />
</code><br />
Maintenant tout fonctionne comme prévu!</p>
<h2>La fin</h2>
<p>Pour finir, ceci montre encore l&#8217;importance des logs lors de la rencontre de problème. S&#8217;il y a moyen penser a les activer, cela simplifie franchement la tâche de débogage que cela soit pour Apache mais aussi pour tout projet informatique.</p>
<p>Un dernier conseil, pensez a désactiver le mode debug de Apache une fois fini!</p>
<p>S&#8217;il y avait un site a conseiller sur ce sujet (en dehors du manuel Apache) je vous renverrait vers <a href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html" target="_blank">askapache</a></p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-289-1'>Si le fichier ne se créer pas tout seul penser à le créer <span class='footnotereverse'><a href='#fnref-289-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/289/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URL rewriting et SEO : duplication de contenu</title>
		<link>http://grummfy.be/blog/268#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/268#comments</comments>
		<pubDate>Wed, 02 Jun 2010 20:09:53 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[référencement]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[url rewriting]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=268</guid>
		<description><![CDATA[Article présentant l'URL rewriting et ce qu'est SEO pour arriver à la problématique de la réécriture d'URL : la duplication de contenu et comment l'éviter.]]></description>
			<content:encoded><![CDATA[<p>Cet article présente rapidement l&#8217;<acronym title="Uniform Resource Locators">URL</acronym> rewriting et ce qu&#8217;est SEO pour arriver au cœur du sujet, à savoir, la problématique de la réécriture d&#8217;URL : la duplication de contenu. Pourquoi la duplication de contenu est gênante et surtout comment l&#8217;éviter sont expliqué dans la suite!<span id="more-268"></span></p>
<h2>Mise en bouche</h2>
<p>L&#8217;URL rewriting ou réécriture d&#8217;<acronym title="Uniform Resource Locators">URL</acronym><sup class='footnote'><a href='#fn-268-1' id='fnref-268-1'>1</a></sup> permet de réécrire de manière plus ou moins dynamique des URL (par exemple transformer http://www.example.com/ en http://example.com/ avec une redirection ou encore http://example.com/contact/moi/par/formulaire en http://example.com/contact.php).</p>
<p>SEO ou Search Engine Optimization consiste à optimiser le référencement d&#8217;un site.</p>
<h2>Exemple</h2>
<p>Afin de débuter, il convient de donner un exemple fonctionnel. Reprenons donc un fichier .htaccess de base :<code><br />
&lt;IfModule mod_rewrite.c&gt;<br />
RewriteEngine on<br />
#si votre fichier se trouve dans /chemin vers votre répertoire de base de votre serveur/test/<br />
RewriteBase /test/<br />
#<br />
#On élimine les fichiers et répertoires qui existent déjà de la réécriture<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
#réécrit l'url<br />
RewriteRule ^(.+)$ index.php?path=$1 [QSA,L]<br />
&lt;/IfModule&gt;<br />
</code><br />
Je suppose que vous tester votre script localement, que vous êtes dans le dossier test et que le fichier php est index.php (qui suit).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">#
</span><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REDIRECT_QUERY_STRING'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REDIRECT_URL'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QUERY_STRING'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/ pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>Si vous testez le script, essayez d&#8217;y accéder par http://localhost/test/ceci-est_un-test?toto=tata puis par http://127.0.0.1/ceci-est_un-test?toto=tata . Dans le deuxième cas, une redirection 301 (fichier bouger de manière permanente) est effectuée. Concernant, l&#8217;explication en détail de la réécriture d&#8217;URL je vous renvoi vers votre moteur de recherche favoris.</p>
<h2>Double accès</h2>
<p>Maintenant, un  problème se pose. En effet, votre site est accessible par plusieurs URL différentes pour un même contenu, les moteurs de recherche interpréteront cela comme du duplicata de contenu <sup class='footnote'><a href='#fn-268-2' id='fnref-268-2'>2</a></sup>! Pour résoudre ce problème, il faut simplement faire en sorte que seule une seule et unique adresse soit accessible.</p>
<p>Premièrement, vérifier que l&#8217;on provient du bon domaine (par exemple : n&#8217;autoriser que example.com et non pas www.example.com ou uniquement localhost et non pas 127.0.0.1), le fichier .htaccess devient :<br />
<code><br />
&lt;IfModule mod_rewrite.c&gt;<br />
RewriteEngine on<br />
#si votre fichier se trouve dans /chemin vers votre répertoire de base de votre serveur/test/<br />
RewriteBase /test/<br />
#<br />
#test si on est bien sur le domaine localhost et non 127.0.0.1 ou autre chose<br />
RewriteCond %{HTTP_HOST} !^localhost<br />
#QSA pour transmettre le query string<br />
#L pour dire de sortir de la boucle de réécriture<br />
#R pour rediriger avec le code HTTP 301<br />
RewriteRule ^(.*) http://localhost/test/$1 [QSA,L,R=301]<br />
#<br />
#On élimine les fichiers et répertoires qui existent déjà de la réécriture<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
#réécrit l'url<br />
RewriteRule ^(.+)$ index.php?path=$1 [QSA,L]<br />
&lt;/IfModule&gt;<br />
</code></p>
<p>Ensuite, il faut dire aux moteurs de recherche de ne pas indexer les URL du genre index.php?mesparametres. Pour cela, on créé ou modifie le fichier robots.txt<sup class='footnote'><a href='#fn-268-3' id='fnref-268-3'>3</a></sup> :<br />
<code>User-agent: *<br />
Disallow: /test/index.php<br />
Allow: /test/</code></p>
<p>Maintenant, si vous testez le script, que cela soit par  http://localhost/test/ceci-est_un-test?toto=tata ou par  http://127.0.0.1/ceci-est_un-test?toto=tata seul localhost est accessible, l&#8217;autre effectue une redirection HTTP 301.</p>
<h2>Le mot de la fin</h2>
<p>Dans le cadre de la réécriture d&#8217;URL, il faut se méfier des possibilités d&#8217;inversion de paramètre. En effet, avec <a href="http://grummfy.be/blog/zend-framework">ZF</a> par exemple, une URL telle que http://example.com/test/controller/action/param1/var1/param2/var2 est équivalente à http://example.com/test/controller/action/param2/var2/param1/var1 mais les moteurs de recherche marqueront le contenu comme dupliqué. Dans ce cas-là, ce n&#8217;est plus du côté d’apache qu&#8217;il faut regarder mais bien du côté du moteur de votre site &#8230;</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-268-1'>On devrait dire <acronym title="Uniform Resource Identifiers">URI</acronym> selon la RFC 3986 mais <acronym title="Tout Le Monde S'En Fout">TLMSF</acronym> <span class='footnotereverse'><a href='#fnref-268-1'>&#8617;</a></span></li>
<li id='fn-268-2'>au pire vous serez blacklinker, au mieux votre référencement en pâtira <span class='footnotereverse'><a href='#fnref-268-2'>&#8617;</a></span></li>
<li id='fn-268-3'>Pour rappel, ce fichier se place à la base de votre URL, soit pour que dans notre exemple (http://www.example.com/test/) le fichier soit accessible via http://www.example.com/robots.txt <span class='footnotereverse'><a href='#fnref-268-3'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/268/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wampserver : quick switch xdebug menu</title>
		<link>http://grummfy.be/blog/250#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/250#comments</comments>
		<pubDate>Wed, 24 Mar 2010 22:22:42 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[deboguage]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[jouons]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[XDebug]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=250</guid>
		<description><![CDATA[Activer et désactiver XDebug sur Wampserver à souhait! Ceci via un menu supplémentaire.]]></description>
			<content:encoded><![CDATA[<p>Pour une fois, un article sous Ms Windows. Stage oblige, je passe du temps sous celui-ci (XP <img src='http://grummfy.be/blog/wp/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  ). Afin d&#8217;optimiser son travail, il y a parfois des petites choses bien pratiques, telles que ce que je vais vous présenter.</p>
<p>XDebug est un outil merveilleux, parfois capricieux, certes, mais très utile. Il permet, notamment<sup class='footnote'><a href='#fn-250-1' id='fnref-250-1'>1</a></sup> :</p>
<ul>
<li>Affichage de tracé d&#8217;erreur</li>
<li>Meilleures lectures des exceptions</li>
<li>Débogage pas-à-pas</li>
<li>Profiling d&#8217;application</li>
<li>&#8230;</li>
</ul>
<p>Bref, des choses essentielles en développement. Et, contrairement à ce que certains IDE<sup class='footnote'><a href='#fn-250-2' id='fnref-250-2'>2</a></sup> font, il permet surtout de le faire sur un serveur &laquo;&nbsp;réel&nbsp;&raquo;, donc avec une utilisation &laquo;&nbsp;réel&nbsp;&raquo;.</p>
<p>Le but de ce billet n&#8217;est pas de présenter XDebug, d&#8217;autres le font mieux que moi <sup class='footnote'><a href='#fn-250-3' id='fnref-250-3'>3</a></sup>, mais bien de vous présenter un petit script vous permettant d&#8217;activer et désactiver XDebug sur wampserver.</p>
<h2>Installation</h2>
<ol>
<li>Téléchargez le fichier <sup class='footnote'><a href='#fn-250-4' id='fnref-250-4'>4</a></sup> et décompressez-le.</li>
<li>Suivez les instructions d&#8217;installation décrite dans le fichier installe. Il y a seulement 1 fichier à modifier + 1 fichier par version de PHP installée.</li>
<li>Relancer wampserver et tester!</li>
</ol>
<p>Si vous avez des questions, n&#8217;hésitez pas.</p>
<h2>Plus d&#8217;informations</h2>
<ul>
<li><a href="http://blog.pascal-martin.fr/post/xdebug-installation-premiers-pas" target="_blank">Xdebug : Installation et premier pas</a></li>
<li><a href="http://blog.wampserver.com/index.php/2009/08/28/debugger-avec-wampserver-xdebug-et-pdt/" target="_self" class="broken_link">Débugger avec WampServer, Xdebug et PDT</a></li>
<li><a href="http://evoilliot.u7n.org/2010/02/installer-xdebug-avec-xampp/" target="_blank" class="broken_link">Installer Xdebug avec XAMPP</a></li>
<li><a href="http://www.wampserver.com" target="_blank">Wampserver</a></li>
<li><a href="http://xdebug.com/" target="_blank">XDebug</a></li>
<li>Pièce jointe : <a href="http://grummfy.be/blog/250/xdebug-tar">XDebug quick switch menu for wampserver</a></li>
</ul>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-250-1'>On parle de serveur web avec PHP &#8230; <span class='footnotereverse'><a href='#fnref-250-1'>&#8617;</a></span></li>
<li id='fn-250-2'>Par exemple, Zend Studio permet un débogage pas à pas mais en interne donc réduit &#8230;  <span class='footnotereverse'><a href='#fnref-250-2'>&#8617;</a></span></li>
<li id='fn-250-3'>cf. plus d&#8217;informations <span class='footnotereverse'><a href='#fnref-250-3'>&#8617;</a></span></li>
<li id='fn-250-4'><a href="http://grummfy.be/blog/250/xdebug-tar">XDebug quick switch menu for wampserver</a> <span class='footnotereverse'><a href='#fnref-250-4'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/250/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Vitesse et référencement</title>
		<link>http://grummfy.be/blog/243#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/243#comments</comments>
		<pubDate>Tue, 23 Mar 2010 09:34:38 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Réflexion du jour]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[référencement]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web sémantique]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=243</guid>
		<description><![CDATA[La vitesse d&#8217;affichage d&#8217;une page web est actuellement, et ce depuis un certain temps, devenu importante. Surtout en ce qui concerne l&#8217;optimisation et par conséquent le référencement. Afin de gagner ces quelques millisecondes qui feront la différence, il existe plusieurs méthodes et techniques. En voici quelques-unes, avec des exemples. Diminuer le nombre de requêtes HTTP [...]]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } 		A:link { so-language: zxx } --></p>
<p>La vitesse d&#8217;affichage d&#8217;une page web est actuellement, et ce depuis un certain temps, devenu importante. Surtout en ce qui concerne l&#8217;optimisation et par conséquent le référencement. Afin de gagner ces quelques millisecondes qui feront la différence, il existe plusieurs méthodes et techniques. En voici quelques-unes, avec des exemples.</p>
<h2>Diminuer le nombre de requêtes HTTP</h2>
<p>Chaque requête HTTP au sein du fichier prend un certain temps, mais surtout bloque le chargement global de la page web. En effet, HTTP et HTML chargent les ressources au fur et à mesure que la page le demande.</p>
<p><span id="more-243"></span></p>
<p>Restreindre le nombre de fichiers, par exemple, en regroupant les css et javascript est une bonne solution. Une autre possibilité est aussi de charger l&#8217;essentiel de la page et à la fin de celle-ci, exécuter du code javascript qui sera chargé de téléverser du javascript ou encore des css.</p>
<h2>Diminuer le nombre de requêtes DNS</h2>
<p>Que dire, si ce n&#8217;est l&#8217;essentiel, une requête DNS prend du temps, et le temps est pris sur le chargement de votre page.</p>
<h2>Se rapprocher du visiteur</h2>
<p>La distance entre un serveur et un visiteur peut faire varier énormément le temps d&#8217;affichage. En effet, une information située sur un serveur a un point X du globe peut parfois faire plusieurs fois le tour de celui-ci avant d&#8217;arriver chez le visiteur Y. Tout dépends des accords entre les gestionnaires des différents réseaux, le chemin le plus économique est celui qui sera choisi<sup class='footnote'><a href='#fn-243-1' id='fnref-243-1'>1</a></sup>!!!!! En résumé, plus vous êtes proches, plus cela arrive vite.</p>
<p>Une solution peut venir de l&#8217;utilisation de <a title="Content Delivery Network" href="http://fr.wikipedia.org/wiki/Content_Delivery_Network" target="_blank">CDN</a> qui suivant la provenance de l&#8217;IP oriente le visiteur vers le serveur le plus proche.</p>
<h2>Diminuer la quantité de données envoyées</h2>
<p>Cela peut paraître bête, mais moins il y a de données, moins il faut attendre pour recevoir celle-ci. Le but n&#8217;est pas de supprimer du contenu, mais bien de faire une diète, par exemple, en optimisant le code (X)HTML, CSS, javascript, &#8230; Ceci en enlevant les espaces superflus et en compressant les données envoyées. On peut notamment citer <a href="http://javascript.crockford.com/jsmin.html" target="_blank">jsmin</a> et <a href="http://yuilibrary.com/downloads/#yuicompressor" target="_blank">YUI Compressor</a></p>
<p>Mais aussi utiliser le mode deflate et gzip de votre serveur web (Apache par exemple). Ceci fera prochainement l&#8217;objet d&#8217;un article.</p>
<h2>Utiliser le cache des navigateurs</h2>
<p>HTTP prévois un mécanisme de cache, pensez à l&#8217;utiliser. Envoyer une bonne entête HTTP sur vos fichiers afin que seul le contenu qui ai changé soit chargé par le visiteur qui revient sur votre site.</p>
<p>Parallèlement à cela, si vous utilisez des librairies ou des framework css ou javascript vous pouvez très bien utiliser un CDN tel que celui que <a href="http://code.google.com/apis/ajaxlibs/documentation/" target="_blank">Google met à votre disposition</a>. Le cache sera le même pour tous les sites qui utiliseront ce CDN et donc le gain « risque » d&#8217;être présent même si le visiteur visite votre site pour la première fois!</p>
<h2>Pour finir</h2>
<p>Et il existe au moins des dizaines d&#8217;autres techniques, c&#8217;est dire si le sujet et étendu et intéressant. Certaines, sont réalisable à l&#8217;échelle de l&#8217;individu tandis que d&#8217;autres nécessitent un investissement, parfois conséquent.</p>
<p>Le but de cet article était d&#8217;intriguer et de vous pousser à aller plus loin. Un web plus rapide est l&#8217;affaire de tous et est bénéfique pour tous : le visiteur, le webmaster, le référencement du site, les FAI (qui paierons moins de bande passante), les hébergeurs, la planète (ben oui, un web optimiser = un web qui consomme moins!), &#8230;</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-243-1'>L&#8217;écologie au niveau d&#8217;internet ce n&#8217;est donc pas ça! Imaginez la consommation de tous ces routeurs et switchs. <span class='footnotereverse'><a href='#fnref-243-1'>&#8617;</a></span></li>
</ol>
</div>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F243&amp;linkname=Vitesse%20et%20r%C3%A9f%C3%A9rencement" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F243&amp;linkname=Vitesse%20et%20r%C3%A9f%C3%A9rencement" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F243&amp;linkname=Vitesse%20et%20r%C3%A9f%C3%A9rencement" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F243&amp;linkname=Vitesse%20et%20r%C3%A9f%C3%A9rencement" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F243&amp;linkname=Vitesse%20et%20r%C3%A9f%C3%A9rencement" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F243&amp;linkname=Vitesse%20et%20r%C3%A9f%C3%A9rencement" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F243&amp;title=Vitesse%20et%20r%C3%A9f%C3%A9rencement" id="wpa2a_10"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/243/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Future &#8230; et projets</title>
		<link>http://grummfy.be/blog/240#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/240#comments</comments>
		<pubDate>Fri, 19 Mar 2010 23:03:52 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Grummfy grrrrumf, ou comment raller]]></category>
		<category><![CDATA[Réflexion du jour]]></category>
		<category><![CDATA[actualité]]></category>
		<category><![CDATA[FSB]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[sortie]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=240</guid>
		<description><![CDATA[Mon blog va évoluer d'ici quelques mois, des changements sont en perspectives.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Mon blog va évoluer d&#8217;ici quelques mois, des changements sont en perspectives.</p>
<p style="text-align: justify;">Tout d&#8217;abord, passons en revue les sujets qui seront abordés. Encore et toujours Zend Framework, je compte continuer de publier. C&#8217;est un sujet qui m&#8217;intéresse et qui je trouve est très intéressant. Par ailleurs, je compte faire une série d&#8217;articles sur CMIS. Si vous ignorez ce que c&#8217;est &#8230; alors tant mieux!<br />
En dehors de ces sujets principaux, seront aussi abordés des projets. Dans ceux-ci on pourra citer principalement deux choses : FSB dont le développement va reprendre (enfin &#8230;) et des projets sous Android.</p>
<p style="text-align: justify;">Bref, des choses intéressantes et alléchantes, mais ce n&#8217;est pas tout! Je compte faire du nettoyage. Hé oui, le printemps arrive, les oiseaux chantent, et certains sortes les balais et les caisses pour le « nettoyage de printemps », ce sera donc mon cas. Depuis trop longtemps, je remet a plus tard de me faire un vrai site avec un contenu qui me correspondent et non des « machins » accumulés et qui date &#8230;</p>
<p>Donc :</p>
<ul>
<li> des projets a réalisé</li>
<li> des sujets à aborder</li>
<li> un site renouvelé</li>
</ul>
<p style="text-align: justify;">Voilà le programme!</p>
<p style="text-align: justify;">Mais aussi, et c&#8217;est une idée qui me trotte dans la tête depuis longtemps, éventuellement un nouveau blog ou site consacré à la cuisine.</p>
<p style="text-align: justify;">Vous avez le menu, reste à savoir si le chef sera dans les temps.</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/240/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Activation, désactivation du wifi sur un D-Link DSL-2640B via PHP</title>
		<link>http://grummfy.be/blog/233#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/233#comments</comments>
		<pubDate>Wed, 17 Mar 2010 23:06:52 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[Logiciel]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Réflexion du jour]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[réseaux]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[wifi]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=233</guid>
		<description><![CDATA[Un script PHP en ligne de commande pour activer // désactiver le wifi sur un modem D-Link DSL-2640B. Cela permet d&#8217;illustrer un peu l&#8217;intérêt de faire du scripting &#8230; Je ne ferais pas de commentaires, mais n&#8217;hésitez pas à poser des questions &#8230; #!/usr/bin/php &#60;?php &#160; //Variable definition // //router $login = 'admin'; $password = [...]]]></description>
			<content:encoded><![CDATA[<p>Un script PHP en ligne de commande pour activer // désactiver le wifi sur un modem D-Link DSL-2640B. Cela permet d&#8217;illustrer un peu l&#8217;intérêt de faire du scripting &#8230;</p>
<p>Je ne ferais pas de commentaires, mais n&#8217;hésitez pas à poser des questions &#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">#!/usr/bin/php
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Variable definition</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//router</span>
<span style="color: #000088;">$login</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'192.168.1.1'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//wifi</span>
<span style="color: #000088;">$wifi</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #666666; font-style: italic;">// /!\ don't touch this /!\</span>
	<span style="color: #0000ff;">'wlSsidIdx'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlEnbl'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlCountry'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GB'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlBasicRate'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//ssid name</span>
	<span style="color: #0000ff;">'wlSsid'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'monSuperRéseauxWifi'</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//0 = visible, 1 = hide</span>
	<span style="color: #0000ff;">'wlHide'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//number of chanel or 0 for auto selection</span>
	<span style="color: #0000ff;">'wlChannel'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//Transmission Speed</span>
	<span style="color: #0000ff;">'wlRate'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//wifi mode 0=802.11b only, 1=Mixed 802.11g and 802.11b, 4=802.11g only</span>
	<span style="color: #0000ff;">'wlgMode'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
&nbsp;
	<span style="color: #0000ff;">'wlWpaGTKRekey'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">750</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlWpa'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'aes'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlAuthMode'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'psk2'</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//authentification mode : 0 = none, 1 = wep, 2 = auto (wpa or wpa2), 3 = wpa2 only, 4 = wpa only</span>
	<span style="color: #0000ff;">'wlAuth'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlWpaPsk'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'masuperclefdelamortquitue'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlWep'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'disabled'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlPreauth'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/////////////////////</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> cli
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">const</span> LINE_BREAK <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> LINE_NO_BREAK <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> LINE_RETURN <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> LINE_NOTHING <span style="color: #339933;">=</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_TEMP</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250000</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//1/4 of seconds</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_MULTIPLICATOR</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//1/4 -&gt; 4</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_LENGTH</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _write_empty_space<span style="color: #009900;">&#40;</span><span style="color: #000088;">$lng</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lng</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_LENGTH<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$lng</span><span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _echo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$break</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$break</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NO_BREAK</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_write_empty_space<span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _sleep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$second</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$second</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$second</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_MULTIPLICATOR<span style="color: #339933;">;</span>
		<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$second</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">usleep</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_TEMP<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NOTHING</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_RETURN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_write_empty_space<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_RETURN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Please wait'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NOTHING</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$j</span><span style="color: #339933;">++;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_RETURN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> wifi <span style="color: #000000; font-weight: bold;">extends</span> cli
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_ch</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_baseUrl</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> <span style="color: #000088;">$login</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$activation</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_baseUrl <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ip</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$login</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$activation</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$activation</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$activation</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_activation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_disactivation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _activation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Activation ...'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NO_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$wifi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wlBasicRate'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wlgMode'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'wifi2'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_doQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_baseUrl <span style="color: #339933;">.</span> <span style="color: #0000ff;">'wirelesssetting.wl?'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_sleep<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _disactivation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Disactivation ...'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NO_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$wifiDown</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'wlEnbl'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'wlSsidIdx'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$wifi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wlSsidIdx'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'wlCountry'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$wifi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wlCountry'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_doQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_baseUrl <span style="color: #339933;">.</span> <span style="color: #0000ff;">'wirelesssetting.wl?'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifiDown</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_sleep<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _doQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_HTTPGET<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error Curl : '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">curl_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DONE'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$login</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Authentification ...'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NO_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'username'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$login</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'password'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$password</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_doQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_baseUrl <span style="color: #339933;">.</span> <span style="color: #0000ff;">'index.html'</span><span style="color: #339933;">,</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$argc</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' synthaxe : scriptname.php 1 for activation or 0 for desactivation '</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">new</span> wifi<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> <span style="color: #000088;">$login</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>Certes, le script ne gère pas tout, mais le but était de jouer avec la ligne de commande tout en n’allant pas dans les extensions exotiques de gestion de celle-ci &#8230;.</p>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;title=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" id="wpa2a_12"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/233/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Planet Zend Framework</title>
		<link>http://grummfy.be/blog/229#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/229#comments</comments>
		<pubDate>Thu, 21 Jan 2010 21:48:38 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=229</guid>
		<description><![CDATA[Un planet sur Zend Framework, pour les francophones est née! Tout d&#8217;abord qu&#8217;est-ce qu&#8217;un planet? Un planet est un agrégateur de flux rss concernant un même sujet. Le but est de promouvoir mais surtout de concentrer les articles publié sur le sujet. Pour ceux qui désirerait y goûter, je vous renvoi vers le site : [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Un planet sur Zend Framework, pour les francophones est née!</p>
<p style="text-align: justify;">Tout d&#8217;abord qu&#8217;est-ce qu&#8217;un planet?<br />
Un planet est un agrégateur de flux rss concernant un même sujet. Le but est de promouvoir mais surtout de concentrer les articles publié sur le sujet.</p>
<p style="text-align: justify;">Pour ceux qui désirerait y goûter, je vous renvoi vers le site : <a title="ZF Planet" href="http://zf-planet.net/fr/" target="_blank">zf planet</a></p>
<p style="text-align: justify;">N&#8217;hésitez pas à demander a en faire partie.</p>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F229&amp;linkname=Planet%20Zend%20Framework" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F229&amp;linkname=Planet%20Zend%20Framework" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F229&amp;linkname=Planet%20Zend%20Framework" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F229&amp;linkname=Planet%20Zend%20Framework" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F229&amp;linkname=Planet%20Zend%20Framework" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F229&amp;linkname=Planet%20Zend%20Framework" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F229&amp;title=Planet%20Zend%20Framework" id="wpa2a_14"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/229/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tri de listing sql via des liens dans Zend Framework</title>
		<link>http://grummfy.be/blog/222#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/222#comments</comments>
		<pubDate>Sun, 10 Jan 2010 02:23:44 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=222</guid>
		<description><![CDATA[Dans la plupart des cas lorsque l'on affiche un listing provenant d'une requête sql on aimerait pouvoir offrir le tri à l'utilisateur. Dans l'article qui suit, je vous propose de découvrir une manière de le faire assez facilement.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Dans la plupart des cas lorsque l&#8217;on affiche un listing provenant d&#8217;une requête sql on aimerait pouvoir offrir le tri à l&#8217;utilisateur. Dans l&#8217;article qui suit, je vous propose de découvrir une manière de le faire assez facilement.</p>
<p><span id="more-222"></span></p>
<p style="text-align: justify;">Comme exemple nous prendrons le cas d&#8217;une liste via l&#8217;appelle du contrôleur membres et de l&#8217;action liste.</p>
<p style="text-align: justify;">Dans le fichier <em>MembresController.php</em> nous aurons donc une méthode <em>listeAction()</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> listeAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$membres</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_DbTable_Membres<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$membres</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Et dans la vue <em>membres/liste.phtml</em> nous aurons :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$rowCount</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rowCount</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;table&gt;
	&lt;tr&gt;
		&lt;th&gt;Nom&lt;/th&gt;
		&lt;th&gt;Adresse&lt;/th&gt;
		&lt;th&gt;Code postal&lt;/th&gt;
		&lt;th&gt;Ville&lt;/th&gt;
		&lt;th&gt;Email&lt;/th&gt;
	&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entrie</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entry</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;tr&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addrese</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postCode</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cityName</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/table&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div&gt;Aucun membre n\'est enregistré!&lt;br /&gt;;)&lt;br /&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Jusque là, normalement, rien de bien complexe pour celui qui connait ZF.</p>
<p style="text-align: justify;">Ajoutons deux fichiers (cf <a rel="attachment wp-att-223" href="http://grummfy.be/blog/222/zf-tuto-order-by">pièce jointe</a>) dans le dossier librairy/Gru.</p>
<p style="text-align: justify;">
Nous devons ensuite les charger de manière automatique. Pour ce faire, dans le bootstrap.php (dont un extrait possible est présent ci-dessous) ajoutons les informations nécessaires au chargement des fichiers :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initAutoload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// nos deux lignes ajoutées</span>
		<span style="color: #000088;">$autoloader</span> <span style="color: #339933;">=</span> Zend_Loader_Autoloader<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$autoloader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Gru'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// fin de l'ajout</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Exemple de ce qu'il pourrait y avoir en plus!</span>
		<span style="color: #000088;">$autoloader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application_Module_Autoloader<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'namespace'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Default'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'basePath'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$autoloader</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initView<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_View<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$viewRenderer</span> <span style="color: #339933;">=</span> Zend_Controller_Action_HelperBroker<span style="color: #339933;">::</span><span style="color: #004000;">getStaticHelper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ViewRenderer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$viewRenderer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setView</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//début ajout</span>
		<span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addHelperPath</span><span style="color: #009900;">&#40;</span>APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/../library/Gru/View/Helper/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Gru_View_Helper_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// fin de l'ajout</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$view</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Maintenant, modifions notre application pour ajouter le tri. Reprenons notre contrôleur et modifions la méthode <em>listeAction().</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> listeAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Gestion du tri</span>
	<span style="color: #000088;">$order</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Gru_OrderBy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'membre'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Ajout des clefs de tri</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Nom'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'add'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Adresse'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'postCode'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Code postal'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cityName'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Ville'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Courriel'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// injection des requêtes get</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertRequestParams</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'order'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'by'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderKeys</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getKeys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000088;">$membres</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_DbTable_Membres<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//ne pas oubleir d'ajouter les champs trier au moment de la requête sql</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$membres</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSqlKeys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Et pour finir notre vue :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$rowCount</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rowCount</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;table&gt;
	&lt;tr&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderBy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">th</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderKeys</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/themes/images/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entrie</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entry</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;tr&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addrese</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postCode</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cityName</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/table&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div&gt;Aucun membre n\'est enregistré!&lt;br /&gt;;)&lt;br /&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Dans l&#8217;exemple, nous afficherons des icônes suivant le sens du tri, icônes se trouvant dans le répertoire spécifié. Un clic sur les titres permet de trier suivant la colonne cliquée. A noter qu&#8217;ici Adresse ne sera pas triable du au fait de la non précision de l&#8217;ordre.</p>
<p style="text-align: justify;">Il y aurait moyen d&#8217;améliorer le script :</p>
<ul>
<li>utilisations de décorateurs</li>
<li>utilisation de traduction</li>
<li>Gru_OrderBy devrait être un plugins</li>
<li>&#8230;</li>
</ul>
<p style="text-align: justify;">En attendant, j&#8217;espère que ce bout de code vous facilitera la vie!</p>
<p style="text-align: justify;">Des remarques, des questions? Postez un commentaire!</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/222/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>[note]Zend Framework et dojo : auto-complétion</title>
		<link>http://grummfy.be/blog/216#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/216#comments</comments>
		<pubDate>Sat, 02 Jan 2010 15:32:29 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=216</guid>
		<description><![CDATA[Ceci est une note rapide ... j'espère produire un article plus intéressant une autre fois ...
Nous allons regarder les bases de l'auto-complétion  avec ZF et Dojo. Dojo simplement parce qu'il est le mieux intégré des frameworks javascript. Sachant que pour l'instant seul jQuery et Dojo sont intégré...]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Ceci est une note rapide &#8230; j&#8217;espère produire un article plus intéressant une autre fois &#8230;</p>
<p style="text-align: justify;">Nous allons regarder les bases de l&#8217;auto-complétion  avec <a href="./?tag=zf#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">ZF</a> et Dojo. Dojo simplement parce qu&#8217;il est le mieux intégré des frameworks javascript. Sachant que pour l&#8217;instant seul jQuery et Dojo sont intégré</p>
<h2>Le code</h2>
<p><em>application/views/scripts/test/index.phtml</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">enable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//activation de dojo</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comboBox</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'toto'</span><span style="color: #339933;">,</span>	<span style="color: #666666; font-style: italic;">//id html de l'élément</span>
	<span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>	<span style="color: #666666; font-style: italic;">//valeur par défaut</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'autocomplete'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>								<span style="color: #666666; font-style: italic;">//activation de l'auto-complétion</span>
		<span style="color: #0000ff;">'store'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'stateStore'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'storeType'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dojo.data.ItemFileReadStore'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'storeParams'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/test/records'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>	<span style="color: #666666; font-style: italic;">//url où les données JSON sont récupérée</span>
		<span style="color: #0000ff;">'searchAttr'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span>								<span style="color: #666666; font-style: italic;">//donnée recherchée pour remplir le combobox</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><em>application/layoutes/scripts/layout.phtml</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// ...</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>	<span style="color: #666666; font-style: italic;">//Évite les chargement inutile ....</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDjConfigOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'isDebug'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>APPLICATION_ENV <span style="color: #339933;">==</span> <span style="color: #0000ff;">'development'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//affiche une console de deboguage si on est en mode dev</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDjConfigOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'usePlainJson'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>						<span style="color: #666666; font-style: italic;">//utilise du json texte</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLocalPath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/themes/js/dojo/dojo/dojo.js'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			<span style="color: #666666; font-style: italic;">//chemin vers les fichier dojo</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addStyleSheetModule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dijit.themes.tundra'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>					<span style="color: #666666; font-style: italic;">//thème à chargé</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>												<span style="color: #666666; font-style: italic;">//affichage du tout ...</span>
		<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// viennent ensuite nos jabvascript, css, etc</span>
<span style="color: #666666; font-style: italic;">//...</span>
<span style="color: #666666; font-style: italic;">//&lt;/head&gt;</span>
<span style="color: #666666; font-style: italic;">// ne pas oublier la class tundra dans le body</span>
<span style="color: #339933;">&lt;</span>body <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tundra&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #666666; font-style: italic;">//...</span></pre></div></div>

<p><em>application/Bootstrap.php</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//...</span>
<span style="color: #666666; font-style: italic;">//dans _initView()</span>
		<span style="color: #666666; font-style: italic;">//dojo</span>
		Zend_Dojo<span style="color: #339933;">::</span><span style="color: #004000;">enableView</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//...</span></pre></div></div>

<p><em>application/controllers/TestController.php</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> TestController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> recordsAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// on désactive l'affichage</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_helper<span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">disableLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//on va cherchée les données et les met dans un objet Zend_Dojo_Data</span>
		<span style="color: #000088;">$book</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_DbTable_Book<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$dojo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Dojo_Data<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$dojo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toJson</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// on sort ... c'est pas joli mais en attendant cela fonctionne!</span>
		<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<h2>Choses à <span style="text-decoration: line-through;">retenir</span> comprendre</h2>
<p>Les choses à retenir :</p>
<ul>
<li><em>storeParams</em> est l&#8217;url où les donnée au format JSON seront prise</li>
<li><em>searchAttr</em> est l&#8217;élément qui va servir pour recherchée les données dans la masse de donnée JSON</li>
<li>ne pas oublier de mettre la class css &#8216;tundra&#8217;</li>
<li>Dojo peut, via ses styles css modifier votre rendu &#8230;</li>
</ul>
<h2>Remarque</h2>
<p>Version de ZF : 1.9.6</p>
<p>Version de Dojo (fourni avec zf dans extras) : 1.3</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/216/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 4.048 seconds -->
<!-- Cached page served by WP-Cache -->

