Go to most recent revision | Blame | Last modification | View Log | RSS feed
<html>
<head>
<title>File Source for Debug.php</title>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
<link rel="stylesheet" type="text/css" href="../media/style.css">
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
<tr>
<td class="header_top">Framework</td>
</tr>
<tr><td class="header_line"><img src="../media/empty.png" width="1" height="1" border="0" alt="" /></td></tr>
<tr>
<td class="header_menu">
[ <a href="../classtrees_Framework.html" class="menu">class tree: Framework</a> ]
[ <a href="../elementindex_Framework.html" class="menu">index: Framework</a> ]
[ <a href="../elementindex.html" class="menu">all elements</a> ]
</td>
</tr>
<tr><td class="header_line"><img src="../media/empty.png" width="1" height="1" border="0" alt="" /></td></tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td width="200" class="menu">
<b>Packages:</b><br />
<a href="../li_Framework.html">Framework</a><br />
<br /><br />
</td>
<td>
<table cellpadding="10" cellspacing="0" width="100%" border="0"><tr><td valign="top">
<h1 align="center">Source for file Debug.php</h1>
<p>Documentation is available at <a href="../Framework/_Debug.php.html">Debug.php</a></p>
<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 fournissant des fonctions de débogage équivalante à var_dump et print_r.</span></div></li>
<li><div class="src-line"><a name="a5"></a><span class="src-doc"> * L'affichage et l'utilisation de ces fonctions sont améliorés via cette classe.</span></div></li>
<li><div class="src-line"><a name="a6"></a><span class="src-doc"> * Cette classe est inspirée de la classe Zend_Debug.</span></div></li>
<li><div class="src-line"><a name="a7"></a><span class="src-doc"> *</span></div></li>
<li><div class="src-line"><a name="a8"></a><span class="src-doc"> * PHP version 5</span></div></li>
<li><div class="src-line"><a name="a9"></a><span class="src-doc"> *</span></div></li>
<li><div class="src-line"><a name="a10"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@category</span><span class="src-doc"> Debogage</span></div></li>
<li><div class="src-line"><a name="a11"></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="a12"></a><span class="src-doc"> // Auteur principal :</span></div></li>
<li><div class="src-line"><a name="a13"></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="a14"></a><span class="src-doc"> // Autres auteurs :</span></div></li>
<li><div class="src-line"><a name="a15"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@license</span><span class="src-doc"> GPL v3 <http://www.gnu.org/licenses/gpl.txt></span></div></li>
<li><div class="src-line"><a name="a16"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@license</span><span class="src-doc"> CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt></span></div></li>
<li><div class="src-line"><a name="a17"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@version</span><span class="src-doc"> $$Id: Debug.php 153 2010-03-04 10:48:32Z jpm $$</span></div></li>
<li><div class="src-line"><a name="a18"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@copyright</span><span class="src-doc"> 1999-2009 Tela Botanica (accueil@tela-botanica.org)</span></div></li>
<li><div class="src-line"><a name="a19"></a><span class="src-doc"> */</span></div></li>
<li><div class="src-line"><a name="a20"></a><span class="src-key">class </span><a href="../Framework/Debug.html">Debug</a> <span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a21"></a> </div></li>
<li><div class="src-line"><a name="a22"></a> <span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a23"></a><span class="src-doc"> * mode de php (cli ou sapi)</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-key">protected </span><span class="src-key">static </span><span class="src-var">$mode </span>= <span class="src-id">null</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a26"></a> </div></li>
<li><div class="src-line"><a name="a27"></a> <span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a28"></a><span class="src-doc"> * Accesseur pour le mode</span></div></li>
<li><div class="src-line"><a name="a29"></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 mode de php</span></div></li>
<li><div class="src-line"><a name="a30"></a><span class="src-doc"> */</span></div></li>
<li><div class="src-line"><a name="a31"></a> <span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Framework/Debug.html#methodgetMode">getMode</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="a32"></a> <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$mode </span>=== <span class="src-id">null</span><span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a33"></a> <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$mode </span>= <span class="src-id">PHP_SAPI</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a34"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a35"></a> <span class="src-key">return </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$mode</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a36"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a37"></a> </div></li>
<li><div class="src-line"><a name="a38"></a> <span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a39"></a><span class="src-doc"> * Equivalent de var_dump</span></div></li>
<li><div class="src-line"><a name="a40"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">mixed </span><span class="src-doc-var">$variable </span><span class="src-doc">la variable à dumper</span></div></li>
<li><div class="src-line"><a name="a41"></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">$mot_cle </span><span class="src-doc">le mot cle à associer à la variable</span></div></li>
<li><div class="src-line"><a name="a42"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">boolean </span><span class="src-doc-var">$echo </span><span class="src-doc">si true on affiche le résultat, si false on ne renvoie que la chaine sans l'afficher</span></div></li>
<li><div class="src-line"><a name="a43"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">la chaine à afficher representant le dump ou null si echo</span></div></li>
<li><div class="src-line"><a name="a44"></a><span class="src-doc"> */</span></div></li>
<li><div class="src-line"><a name="a45"></a> <span class="src-key">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Framework/Debug.html#methoddump">dump</a><span class="src-sym">(</span><span class="src-var">$variable</span><span class="src-sym">, </span><span class="src-var">$mot_cle </span>= <span class="src-id">null</span><span class="src-sym">, </span><span class="src-var">$echo </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="a46"></a> <span class="src-comm">// var_dump de la variable dans un buffer et récupération de la sortie</span></div></li>
<li><div class="src-line"><a name="a47"></a> <span class="src-id">ob_start</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="a48"></a> <a href="http://www.php.net/var_dump">var_dump</a><span class="src-sym">(</span><span class="src-var">$variable</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a49"></a> <span class="src-var">$sortie </span>= <a href="http://www.php.net/ob_get_clean">ob_get_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> </div></li>
<li><div class="src-line"><a name="a51"></a> <span class="src-comm">// Pré-traitement de la sortie</span></div></li>
<li><div class="src-line"><a name="a52"></a> <span class="src-var">$sortie </span>= <a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">"/\]\=\>\n(\s+)/m"</span><span class="src-sym">, </span><span class="src-str">"] => "</span><span class="src-sym">, </span><span class="src-var">$sortie</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a53"></a> </div></li>
<li><div class="src-line"><a name="a54"></a> <span class="src-comm">// Traitement général du débogage</span></div></li>
<li><div class="src-line"><a name="a55"></a> <span class="src-key">return </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">traiterDebogage</span><span class="src-sym">(</span><span class="src-var">$mot_cle</span><span class="src-sym">, </span><span class="src-var">$sortie</span><span class="src-sym">, </span><span class="src-var">$echo</span><span class="src-sym">)</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"> * Equivalent de print_r</span></div></li>
<li><div class="src-line"><a name="a60"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">mixed </span><span class="src-doc-var">$variable </span><span class="src-doc">la variable à afficher</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">$mot_cle </span><span class="src-doc">le mot cle à associer</span></div></li>
<li><div class="src-line"><a name="a62"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">boolean </span><span class="src-doc-var">$echo </span><span class="src-doc">faire un echo ou non</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">la chaine contenant la variable printée ou null si echo</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">public </span><span class="src-key">static </span><span class="src-key">function </span><a href="../Framework/Debug.html#methodprintr">printr</a><span class="src-sym">(</span><span class="src-var">$variable</span><span class="src-sym">, </span><span class="src-var">$mot_cle </span>= <span class="src-id">null</span><span class="src-sym">, </span><span class="src-var">$echo </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="a66"></a> <span class="src-comm">// Récupération de la sortie</span></div></li>
<li><div class="src-line"><a name="a67"></a> <span class="src-var">$sortie </span>= <a href="http://www.php.net/print_r">print_r</a><span class="src-sym">(</span><span class="src-var">$variable</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="a68"></a> </div></li>
<li><div class="src-line"><a name="a69"></a> <span class="src-comm">// Traitement général du débogage</span></div></li>
<li><div class="src-line"><a name="a70"></a> <span class="src-key">return </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">traiterDebogage</span><span class="src-sym">(</span><span class="src-var">$mot_cle</span><span class="src-sym">, </span><span class="src-var">$sortie</span><span class="src-sym">, </span><span class="src-var">$echo</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-sym">}</span></div></li>
<li><div class="src-line"><a name="a72"></a> </div></li>
<li><div class="src-line"><a name="a73"></a> <span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a74"></a><span class="src-doc"> * Traite une chaine de débogage et les mots clés associés</span></div></li>
<li><div class="src-line"><a name="a75"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc"> </span><span class="src-doc-var">$mot_cle </span><span class="src-doc">le mot à associer à la chaine</span></div></li>
<li><div class="src-line"><a name="a76"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc"> </span><span class="src-doc-var">$sortie </span><span class="src-doc">le chaine de debogage</span></div></li>
<li><div class="src-line"><a name="a77"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">boolean </span><span class="src-doc-var">$echo </span><span class="src-doc">faire un echo du resultat ou non</span></div></li>
<li><div class="src-line"><a name="a78"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">la chaine de debogage formatée ou bien null si echo</span></div></li>
<li><div class="src-line"><a name="a79"></a><span class="src-doc"> */</span></div></li>
<li><div class="src-line"><a name="a80"></a> <span class="src-key">private </span><span class="src-key">static </span><span class="src-key">function </span><span class="src-id">traiterDebogage</span><span class="src-sym">(</span><span class="src-var">$mot_cle</span><span class="src-sym">, </span><span class="src-var">$sortie</span><span class="src-sym">, </span><span class="src-var">$echo</span><span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a81"></a> <span class="src-comm">// Formate le mot-clé</span></div></li>
<li><div class="src-line"><a name="a82"></a> <span class="src-var">$mot_cle </span>= <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">formaterMotCle</span><span class="src-sym">(</span><span class="src-var">$mot_cle</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a83"></a> </div></li>
<li><div class="src-line"><a name="a84"></a> <span class="src-comm">// Traitement de la sortie</span></div></li>
<li><div class="src-line"><a name="a85"></a> <span class="src-var">$sortie </span>= <span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">traiterSortieSuivantMode</span><span class="src-sym">(</span><span class="src-var">$mot_cle</span><span class="src-sym">, </span><span class="src-var">$sortie</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a86"></a> </div></li>
<li><div class="src-line"><a name="a87"></a> <span class="src-comm">// Affichage et/ou retour</span></div></li>
<li><div class="src-line"><a name="a88"></a> <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$echo</span><span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a89"></a> echo <span class="src-var">$sortie</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a90"></a> <span class="src-key">return </span><span class="src-id">null</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a91"></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="a92"></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="a93"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a94"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a95"></a> </div></li>
<li><div class="src-line"><a name="a96"></a> <span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a97"></a><span class="src-doc"> * formate un mot clé donné</span></div></li>
<li><div class="src-line"><a name="a98"></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">$mot_cle </span><span class="src-doc">le mot clé à formaté</span></div></li>
<li><div class="src-line"><a name="a99"></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 mot clé formaté ou bien un chaine vide le mot clé est null ou vide</span></div></li>
<li><div class="src-line"><a name="a100"></a><span class="src-doc"> */</span></div></li>
<li><div class="src-line"><a name="a101"></a> <span class="src-key">private </span><span class="src-key">static </span><span class="src-key">function </span><span class="src-id">formaterMotCle</span><span class="src-sym">(</span><span class="src-var">$mot_cle</span><span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a102"></a> <span class="src-key">return </span><span class="src-sym">(</span><span class="src-var">$mot_cle </span>=== <span class="src-id">null</span><span class="src-sym">) </span>? <span class="src-str">'' </span>: <a href="http://www.php.net/rtrim">rtrim</a><span class="src-sym">(</span><span class="src-var">$mot_cle</span><span class="src-sym">)</span>.<span class="src-str">' '</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a103"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a104"></a> </div></li>
<li><div class="src-line"><a name="a105"></a> <span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a106"></a><span class="src-doc"> * traite la sortie de la chaine de débogage suivant le mode de php</span></div></li>
<li><div class="src-line"><a name="a107"></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">$mot_cle </span><span class="src-doc">le mot clé associé à la chaine</span></div></li>
<li><div class="src-line"><a name="a108"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string </span><span class="src-doc"> </span><span class="src-doc-var">$sortie </span><span class="src-doc">la chaine de débogage</span></div></li>
<li><div class="src-line"><a name="a109"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@return </span><span class="src-doc-type">string </span><span class="src-doc">la sortie formatée pour le mode en cours</span></div></li>
<li><div class="src-line"><a name="a110"></a><span class="src-doc"> */</span></div></li>
<li><div class="src-line"><a name="a111"></a> <span class="src-key">private </span><span class="src-key">static </span><span class="src-key">function </span><span class="src-id">traiterSortieSuivantMode</span><span class="src-sym">(</span><span class="src-var">$mot_cle</span><span class="src-sym">, </span><span class="src-var">$sortie</span><span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a112"></a> <span class="src-var">$corps </span>= <span class="src-var">$mot_cle</span>.<span class="src-id">PHP_EOL</span>.<span class="src-var">$sortie</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a113"></a> <span class="src-key">if </span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">getMode</span><span class="src-sym">(</span><span class="src-sym">) </span>== <span class="src-str">'cli'</span><span class="src-sym">) </span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a114"></a> <span class="src-var">$sortie </span>= <span class="src-id">PHP_EOL</span>.<span class="src-var">$corps</span>.<span class="src-id">PHP_EOL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a115"></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="a116"></a> <span class="src-var">$sortie </span>= <span class="src-str">'<pre>'</span>.<span class="src-var">$corps</span>.<span class="src-str">'</pre>'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a117"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a118"></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="a119"></a> <span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a120"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a121"></a><span class="src-php">?></span></div></li>
</ol>
</div>
<div class="credit">
<hr />
Documentation generated on Thu, 04 Mar 2010 19:27:32 +0100 by <a href="http://www.phpdoc.org">phpDocumentor 1.4.3</a>
</div>
</td></tr></table>
</td>
</tr>
</table>
</body>
</html>