Go to most recent revision | Blame | Last modification | View Log | RSS feed
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- template designed by Marco Von Ballmoos -->
<title>File Source for SquelettePhp.php</title>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
<link rel="stylesheet" href="../media/stylesheet.css" />
</head>
<body>
<h1>Source for file SquelettePhp.php</h1>
<p>Documentation is available at <a href="../Framework/_SquelettePhp.php.html">SquelettePhp.php</a></p>
<div class="src-code">
<div class="src-code"><ol><li><div class="src-line"><a name="a1"></a><span class="src-php"><?php</span></div></li>
<li><div class="src-line"><a name="a2"></a><span class="src-comm">// declare(encoding='UTF-8');</span></div></li>
<li><div class="src-line"><a name="a3"></a><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a4"></a><span class="src-doc"> * Classe SquelettePhp, traitant les squelette Php utilisant la syntaxe courte php ou pas.</span></div></li>
<li><div class="src-line"><a name="a5"></a><span class="src-doc"> * Ces méthodes sont statiques.</span></div></li>
<li><div class="src-line"><a name="a6"></a><span class="src-doc"> *</span></div></li>
<li><div class="src-line"><a name="a7"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@category</span><span class="src-doc"> php5</span></div></li>
<li><div class="src-line"><a name="a8"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@package</span><span class="src-doc"> Framework</span></div></li>
<li><div class="src-line"><a name="a9"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@author</span><span class="src-doc"> Jean-Pascal MILCENT <jpm@tela-botanica.org></span></div></li>
<li><div class="src-line"><a name="a10"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@copyright</span><span class="src-doc"> 2010 Tela-Botanica</span></div></li>
<li><div class="src-line"><a name="a11"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@license</span><span class="src-doc"> http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL</span></div></li>
<li><div class="src-line"><a name="a12"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@license</span><span class="src-doc"> http://www.gnu.org/licenses/gpl.html Licence GNU-GPL</span></div></li>
<li><div class="src-line"><a name="a13"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@version</span><span class="src-doc"> SVN: $$Id: SquelettePhp.php 153 2010-03-04 10:48:32Z jpm $$</span></div></li>
<li><div class="src-line"><a name="a14"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@link</span><span class="src-doc"> /doc/framework/</span></div></li>
<li><div class="src-line"><a name="a15"></a><span class="src-doc"> */</span></div></li>
<li><div class="src-line"><a name="a16"></a><span class="src-key">class </span><a href="../Framework/SquelettePhp.html">SquelettePhp</a> <span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a17"></a> </div></li>
<li><div class="src-line"><a name="a18"></a> <span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a19"></a><span class="src-doc"> * Fonction prenant en paramètre un chemin de fichier squelette et un tableau associatif de données,</span></div></li>
<li><div class="src-line"><a name="a20"></a><span class="src-doc"> * en extrait les variables, charge le squelette et retourne le résultat des deux combinés.</span></div></li>
<li><div class="src-line"><a name="a21"></a><span class="src-doc"> *</span></div></li>
<li><div class="src-line"><a name="a22"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">String </span><span class="src-doc-var">$fichier </span><span class="src-doc"> le chemin du fichier du squelette</span></div></li>
<li><div class="src-line"><a name="a23"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">Array </span><span class="src-doc"> </span><span class="src-doc-var">$donnees </span><span class="src-doc"> un tableau associatif contenant les variables a injecter dans le squelette.</span></div></li>
<li><div class="src-line"><a name="a24"></a><span class="src-doc"> *</span></div></li>
<li><div class="src-line"><a name="a25"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">boolean </span><span class="src-doc">false si la vue n'existe pas, sinon la chaine résultat.</span></div></li>
<li><div class="src-line"><a name="a26"></a><span class="src-doc"> */</span></div></li>
<li><div class="src-line"><a name="a27"></a> <span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Framework/SquelettePhp.html#methodanalyser">analyser</a><span class="src-sym">(</span><span class="src-var">$fichier</span><span class="src-sym">, </span><span class="src-key">Array </span><span class="src-var">$donnees </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a28"></a> <span class="src-var">$sortie </span>= <span class="src-id">false</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a29"></a> <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/file_exists">file_exists</a><span class="src-sym">(</span><span class="src-var">$fichier</span><span class="src-sym">)) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a30"></a> <span class="src-comm">// Extraction des variables du tableau de données</span></div></li>
<li><div class="src-line"><a name="a31"></a> <a href="http://www.php.net/extract">extract</a><span class="src-sym">(</span><span class="src-var">$donnees</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a32"></a> <span class="src-comm">// Démarage de la bufferisation de sortie</span></div></li>
<li><div class="src-line"><a name="a33"></a> <a href="http://www.php.net/ob_start">ob_start</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a34"></a> <span class="src-comm">// Si les tags courts sont activés</span></div></li>
<li><div class="src-line"><a name="a35"></a> <span class="src-key">if </span><span class="src-sym">(</span>(bool) <span class="src-sym">@</span><a href="http://www.php.net/ini_get">ini_get</a><span class="src-sym">(</span><span class="src-str">'short_open_tag'</span><span class="src-sym">) </span>=== <span class="src-id">true</span><span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a36"></a> <span class="src-comm">// Simple inclusion du squelette</span></div></li>
<li><div class="src-line"><a name="a37"></a> <span class="src-inc">include </span><span class="src-var">$fichier</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a38"></a> <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a39"></a> <span class="src-comm">// Sinon, remplacement des tags courts par la syntaxe classique avec echo</span></div></li>
<li><div class="src-line"><a name="a40"></a> <span class="src-var">$html_et_code_php </span>= <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">traiterTagsCourts</span><span class="src-sym">(</span><span class="src-var">$fichier</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a41"></a> <span class="src-comm">// Pour évaluer du php mélangé dans du html il est nécessaire de fermer la balise php ouverte par eval</span></div></li>
<li><div class="src-line"><a name="a42"></a> <span class="src-var">$html_et_code_php </span>= <span class="src-str">'?>'</span>.<span class="src-var">$html_et_code_php</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a43"></a> <span class="src-comm">// Interprétation du html et du php dans le buffer</span></div></li>
<li><div class="src-line"><a name="a44"></a> echo eval<span class="src-sym">(</span><span class="src-var">$html_et_code_php</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a45"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a46"></a> <span class="src-comm">// Récupèration du contenu du buffer</span></div></li>
<li><div class="src-line"><a name="a47"></a> <span class="src-var">$sortie </span>= <a href="http://www.php.net/ob_get_contents">ob_get_contents</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a48"></a> <span class="src-comm">// Suppression du buffer</span></div></li>
<li><div class="src-line"><a name="a49"></a> <span class="src-sym">@</span><a href="http://www.php.net/ob_end_clean">ob_end_clean</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a50"></a> <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a51"></a> <span class="src-var">$msg </span>= <span class="src-str">"</span><span class="src-str">Le fichier du squelette '<span class="src-var">$fichier</span>' n'existe pas.</span><span class="src-str">"</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a52"></a> <a href="http://www.php.net/trigger_error">trigger_error</a><span class="src-sym">(</span><span class="src-var">$msg</span><span class="src-sym">, </span><span class="src-id">E_USER_WARNING</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a53"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a54"></a> <span class="src-comm">// Retourne le contenu</span></div></li>
<li><div class="src-line"><a name="a55"></a> <span class="src-key">return </span><span class="src-var">$sortie</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a56"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a57"></a> </div></li>
<li><div class="src-line"><a name="a58"></a> <span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a59"></a><span class="src-doc"> * Fonction chargeant le contenu du squelette et remplaçant les tags court php (<?= ...) par un tag long avec echo.</span></div></li>
<li><div class="src-line"><a name="a60"></a><span class="src-doc"> *</span></div></li>
<li><div class="src-line"><a name="a61"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">String </span><span class="src-doc-var">$chemin_squelette </span><span class="src-doc">le chemin du fichier du squelette</span></div></li>
<li><div class="src-line"><a name="a62"></a><span class="src-doc"> *</span></div></li>
<li><div class="src-line"><a name="a63"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">le contenu du fichier du squelette php avec les tags courts remplacés.</span></div></li>
<li><div class="src-line"><a name="a64"></a><span class="src-doc"> */</span></div></li>
<li><div class="src-line"><a name="a65"></a> <span class="src-key">private </span><span class="src-key">static </span><span class="src-key">function </span><span class="src-id">traiterTagsCourts</span><span class="src-sym">(</span><span class="src-var">$chemin_squelette</span><span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a66"></a> <span class="src-var">$contenu </span>= <a href="http://www.php.net/file_get_contents">file_get_contents</a><span class="src-sym">(</span><span class="src-var">$chemin_squelette</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a67"></a> <span class="src-comm">// Remplacement de tags courts par un tag long avec echo</span></div></li>
<li><div class="src-line"><a name="a68"></a> <span class="src-var">$contenu </span>= <a href="http://www.php.net/str_replace">str_replace</a><span class="src-sym">(</span><span class="src-str">'<?='</span><span class="src-sym">, </span><span class="src-str">'<?php echo '</span><span class="src-sym">, </span><span class="src-var">$contenu</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a69"></a> <span class="src-comm">// Ajout systématique d'un point virgule avant la fermeture php</span></div></li>
<li><div class="src-line"><a name="a70"></a> <span class="src-var">$contenu </span>= <a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">"/;*\s*\?>/"</span><span class="src-sym">, </span><span class="src-str">"; ?>"</span><span class="src-sym">, </span><span class="src-var">$contenu</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a71"></a> <span class="src-key">return </span><span class="src-var">$contenu</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a72"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a73"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a74"></a><span class="src-php">?></span></div></li>
</ol></div>
</div>
<p class="notes" id="credit">
Documentation generated on Thu, 04 Mar 2010 19:27:25 +0100 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.3</a>
</p>
</body>
</html>