156 |
jpm |
1 |
<?php
|
|
|
2 |
/*vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
4 |
// | PHP version 4.3 |
|
|
|
5 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
|
|
|
7 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
8 |
// | This file is part of Papyrus. |
|
|
|
9 |
// | |
|
|
|
10 |
// | Foobar is free software; you can redistribute it and/or modify |
|
|
|
11 |
// | it under the terms of the GNU General Public License as published by |
|
|
|
12 |
// | the Free Software Foundation; either version 2 of the License, or |
|
|
|
13 |
// | (at your option) any later version. |
|
|
|
14 |
// | |
|
|
|
15 |
// | Foobar is distributed in the hope that it will be useful, |
|
|
|
16 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
17 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
18 |
// | GNU General Public License for more details. |
|
|
|
19 |
// | |
|
|
|
20 |
// | You should have received a copy of the GNU General Public License |
|
|
|
21 |
// | along with Foobar; if not, write to the Free Software |
|
|
|
22 |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
|
23 |
// +------------------------------------------------------------------------------------------------------+
|
1536 |
jp_milcent |
24 |
// CVS : $Id: BOG_Gestionnaire_Erreur.class.php,v 1.6.2.1 2007-08-07 09:45:21 jp_milcent Exp $
|
156 |
jpm |
25 |
/**
|
|
|
26 |
* Classe permettant de créer un gestionnaire d'erreur PHP
|
|
|
27 |
*
|
|
|
28 |
* La classe permet de créer un gestionnaire d'erreur PHP et de le configurer.
|
|
|
29 |
*
|
|
|
30 |
*@package Debogage
|
|
|
31 |
//Auteur original :
|
|
|
32 |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
33 |
//Autres auteurs :
|
|
|
34 |
*@author Aucun
|
|
|
35 |
*@copyright Tela-Botanica 2000-2004
|
1536 |
jp_milcent |
36 |
*@version $Revision: 1.6.2.1 $ $Date: 2007-08-07 09:45:21 $
|
156 |
jpm |
37 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
38 |
*/
|
|
|
39 |
|
|
|
40 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
41 |
// | ENTETE du PROGRAMME |
|
|
|
42 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
46 |
// | CORPS du PROGRAMME |
|
|
|
47 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
48 |
class BOG_Gestionnaire_Erreur {
|
|
|
49 |
// Attributs
|
|
|
50 |
var $tab_erreurs = array();
|
|
|
51 |
var $erreur_txt_tete = '';
|
|
|
52 |
var $erreur_txt_pied = '';
|
|
|
53 |
var $bln_contexte = false;
|
|
|
54 |
var $langue = 'fr';
|
|
|
55 |
var $aso_trad = array( 'niveau'=> 'Niveau d\'erreur : ', 'fichier' => 'Nom du fichier : ',
|
|
|
56 |
'ligne' => 'N° de ligne : ', 'contexte' => 'Contexte d\'erreur : ');
|
|
|
57 |
var $class = 'erreur';
|
444 |
ddelon |
58 |
var $active = 1;
|
156 |
jpm |
59 |
|
|
|
60 |
// Constructeur
|
|
|
61 |
function BOG_Gestionnaire_Erreur($bln_contexte, $class = '', $langue = 'fr', $txt_tete = '', $txt_pied = '', $aso_trad = array())
|
|
|
62 |
{
|
|
|
63 |
$this->ecrireContexte($bln_contexte);
|
|
|
64 |
$this->ecrireLangue($langue);
|
|
|
65 |
$this->ecrireTxtTete($txt_tete);
|
|
|
66 |
$this->ecrireTxtPied($txt_pied);
|
|
|
67 |
if (count($aso_trad) != 0) {
|
|
|
68 |
$this->ecrireTraduction($aso_trad);
|
|
|
69 |
}
|
|
|
70 |
if (! empty($class)) {
|
|
|
71 |
$this->ecrireClass($class);
|
|
|
72 |
}
|
443 |
ddelon |
73 |
|
156 |
jpm |
74 |
set_error_handler(array(&$this, 'gererErreur'));
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
// Accesseurs
|
444 |
ddelon |
78 |
|
|
|
79 |
function setActive($active)
|
|
|
80 |
{
|
|
|
81 |
$this->active=$active;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
|
156 |
jpm |
85 |
function ecrireErreur($aso_erreur)
|
|
|
86 |
{
|
|
|
87 |
array_push($this->tab_erreurs, $aso_erreur);
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
function lireTableauErreurs()
|
|
|
91 |
{
|
|
|
92 |
return $this->tab_erreurs;
|
|
|
93 |
}
|
|
|
94 |
function lireTxtTete()
|
|
|
95 |
{
|
|
|
96 |
return $this->erreur_txt_tete;
|
|
|
97 |
}
|
|
|
98 |
function ecrireTxtTete($txt_tete)
|
|
|
99 |
{
|
|
|
100 |
$this->erreur_txt_tete = $txt_tete;
|
|
|
101 |
}
|
|
|
102 |
function lireTxtPied()
|
|
|
103 |
{
|
|
|
104 |
return $this->erreur_txt_pied;
|
|
|
105 |
}
|
|
|
106 |
function ecrireTxtPied($txt_pied)
|
|
|
107 |
{
|
|
|
108 |
$this->erreur_txt_pied = $txt_pied;
|
|
|
109 |
}
|
|
|
110 |
function lireContexte()
|
|
|
111 |
{
|
|
|
112 |
return $this->bln_contexte;
|
|
|
113 |
}
|
|
|
114 |
function ecrireContexte($bln)
|
|
|
115 |
{
|
|
|
116 |
$this->bln_contexte = $bln;
|
|
|
117 |
}
|
|
|
118 |
function lireTraduction($cle)
|
|
|
119 |
{
|
|
|
120 |
return $this->aso_trad[$cle];
|
|
|
121 |
}
|
|
|
122 |
function ecrireTraduction($tab_trad)
|
|
|
123 |
{
|
|
|
124 |
$aso_trad['niveau'] = $tab_trad[0];
|
|
|
125 |
$aso_trad['fichier'] = $tab_trad[1];
|
|
|
126 |
$aso_trad['ligne'] = $tab_trad[2];
|
|
|
127 |
$aso_trad['contexte'] = $tab_trad[3];
|
|
|
128 |
$this->aso_trad = $aso_trad;
|
|
|
129 |
}
|
|
|
130 |
function lireClass()
|
|
|
131 |
{
|
|
|
132 |
return $this->class;
|
|
|
133 |
}
|
|
|
134 |
function ecrireClass($class)
|
|
|
135 |
{
|
|
|
136 |
$this->class = $class;
|
|
|
137 |
}
|
|
|
138 |
function lireLangue()
|
|
|
139 |
{
|
|
|
140 |
return $this->langue;
|
|
|
141 |
}
|
|
|
142 |
function ecrireLangue($langue)
|
|
|
143 |
{
|
|
|
144 |
$this->langue = $langue;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
// Méthode
|
189 |
jpm |
148 |
function gererErreur($niveau, $message, $fichier, $ligne, $contexte)
|
156 |
jpm |
149 |
{
|
444 |
ddelon |
150 |
if ($this->active) {
|
|
|
151 |
// Ouais bof le test, mais php5 renvoie vraiment trop de message d'erreur sur Deprecated ... et
|
|
|
152 |
// ca concerne essentiellement les classes pear !
|
|
|
153 |
|
|
|
154 |
if (!defined('E_STRICT')) {
|
|
|
155 |
define("E_STRICT", 2048);
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
if ($niveau < E_STRICT) {
|
|
|
159 |
|
|
|
160 |
$aso_erreur = array();
|
|
|
161 |
$aso_erreur['niveau'] = $niveau;
|
|
|
162 |
$aso_erreur['message'] = $message;
|
|
|
163 |
$aso_erreur['fichier'] = $fichier;
|
|
|
164 |
$aso_erreur['ligne'] = $ligne;
|
|
|
165 |
if ($this->lireContexte()) {
|
|
|
166 |
$aso_erreur['contexte'] = $contexte;
|
|
|
167 |
}
|
|
|
168 |
$this->ecrireErreur($aso_erreur);
|
|
|
169 |
|
|
|
170 |
}
|
443 |
ddelon |
171 |
}
|
156 |
jpm |
172 |
}
|
|
|
173 |
|
|
|
174 |
function retournerErreurs()
|
|
|
175 |
{
|
1238 |
jp_milcent |
176 |
$contenu = '';
|
156 |
jpm |
177 |
foreach($this->lireTableauErreurs() as $aso_erreur) {
|
1238 |
jp_milcent |
178 |
switch (PAP_DEBOGAGE_TYPE) {
|
|
|
179 |
case 'FIREBUG':
|
|
|
180 |
$contenu .= "console.info(\"[Buggy] - ".
|
|
|
181 |
"Niveau : ".$aso_erreur['niveau']." - ".
|
|
|
182 |
"Fichier : ".$aso_erreur['fichier']." - ".
|
|
|
183 |
"Ligne :".$aso_erreur['ligne']." - ".
|
|
|
184 |
"Message : ".$aso_erreur['message']." - ".
|
|
|
185 |
"\");\n";
|
|
|
186 |
break;
|
|
|
187 |
case 'HTML':
|
|
|
188 |
default:
|
|
|
189 |
$contenu .= '<p class="'.$this->lireClass().'">'."\n";
|
|
|
190 |
$contenu .= '<strong>'.$this->lireTxtTete().$aso_erreur['message'].$this->lireTxtPied().'</strong><br />'."\n";
|
|
|
191 |
$contenu .= '<strong>'.$this->lireTraduction('niveau').'</strong>'.$aso_erreur['niveau'].'<br />'."\n";
|
|
|
192 |
$contenu .= '<strong>'.$this->lireTraduction('fichier').'</strong>'.$aso_erreur['fichier'].'<br />'."\n";
|
|
|
193 |
$contenu .= '<strong>'.$this->lireTraduction('ligne').'</strong>'.$aso_erreur['ligne'].'<br />'."\n";
|
|
|
194 |
if ($this->lireContexte()) {
|
|
|
195 |
$contenu .= '<pre>'."\n";
|
|
|
196 |
$contenu .= '<stong>'.$this->lireTraduction('contexte').'</stong>'.print_r($aso_erreur['contexte'], true)."\n";
|
|
|
197 |
$contenu .= '</pre>'."\n";
|
|
|
198 |
}
|
|
|
199 |
$contenu .= '</p>'."\n";
|
156 |
jpm |
200 |
}
|
1238 |
jp_milcent |
201 |
|
156 |
jpm |
202 |
}
|
1238 |
jp_milcent |
203 |
switch (PAP_DEBOGAGE_TYPE) {
|
|
|
204 |
case 'FIREBUG':
|
1536 |
jp_milcent |
205 |
$retour = '<script type="text/javascript">'."\n".$contenu.'</script>'."\n";
|
1238 |
jp_milcent |
206 |
break;
|
|
|
207 |
case 'HTML':
|
|
|
208 |
default:
|
|
|
209 |
$retour = $contenu;
|
|
|
210 |
}
|
156 |
jpm |
211 |
return $retour;
|
|
|
212 |
}
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
217 |
// | PIED du PROGRAMME |
|
|
|
218 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
/* +--Fin du code ----------------------------------------------------------------------------------------+
|
|
|
222 |
*
|
|
|
223 |
* $Log: not supported by cvs2svn $
|
1536 |
jp_milcent |
224 |
* Revision 1.6 2007-03-01 11:07:43 jp_milcent
|
|
|
225 |
* Gestion de deux types de débogage : html ou firebug.
|
|
|
226 |
*
|
1238 |
jp_milcent |
227 |
* Revision 1.5 2005/09/20 20:25:39 ddelon
|
|
|
228 |
* php5 et bugs divers
|
|
|
229 |
*
|
444 |
ddelon |
230 |
* Revision 1.4 2005/09/20 17:01:22 ddelon
|
|
|
231 |
* php5 et bugs divers
|
|
|
232 |
*
|
443 |
ddelon |
233 |
* Revision 1.3 2004/11/29 15:56:23 jpm
|
|
|
234 |
* Correction bogue.
|
|
|
235 |
*
|
189 |
jpm |
236 |
* Revision 1.2 2004/11/29 15:54:16 jpm
|
|
|
237 |
* Changement de nom de variable et légère correction.
|
|
|
238 |
*
|
187 |
jpm |
239 |
* Revision 1.1 2004/11/15 17:12:46 jpm
|
|
|
240 |
* Classe de gestion d'erreur pour PHP 4.3
|
156 |
jpm |
241 |
*
|
187 |
jpm |
242 |
*
|
156 |
jpm |
243 |
* +-- Fin du code ----------------------------------------------------------------------------------------+
|
|
|
244 |
*/
|
|
|
245 |
?>
|