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 |
// +------------------------------------------------------------------------------------------------------+
|
444 |
ddelon |
24 |
// CVS : $Id: BOG_Gestionnaire_Erreur.class.php,v 1.5 2005-09-20 20:25:39 ddelon 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
|
444 |
ddelon |
36 |
*@version $Revision: 1.5 $ $Date: 2005-09-20 20:25:39 $
|
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 |
{
|
|
|
176 |
$retour = '';
|
|
|
177 |
foreach($this->lireTableauErreurs() as $aso_erreur) {
|
|
|
178 |
$retour .= '<p class="'.$this->lireClass().'">'."\n";
|
|
|
179 |
$retour .= '<strong>'.$this->lireTxtTete().$aso_erreur['message'].$this->lireTxtPied().'</strong><br />'."\n";
|
|
|
180 |
$retour .= '<strong>'.$this->lireTraduction('niveau').'</strong>'.$aso_erreur['niveau'].'<br />'."\n";
|
|
|
181 |
$retour .= '<strong>'.$this->lireTraduction('fichier').'</strong>'.$aso_erreur['fichier'].'<br />'."\n";
|
|
|
182 |
$retour .= '<strong>'.$this->lireTraduction('ligne').'</strong>'.$aso_erreur['ligne'].'<br />'."\n";
|
|
|
183 |
if ($this->lireContexte()) {
|
|
|
184 |
$retour .= '<pre>'."\n";
|
|
|
185 |
$retour .= '<stong>'.$this->lireTraduction('contexte').'</stong>'.print_r($aso_erreur['contexte'], true)."\n";
|
|
|
186 |
$retour .= '</pre>'."\n";
|
|
|
187 |
}
|
|
|
188 |
$retour .= '</p>'."\n";
|
|
|
189 |
}
|
|
|
190 |
return $retour;
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
196 |
// | PIED du PROGRAMME |
|
|
|
197 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
/* +--Fin du code ----------------------------------------------------------------------------------------+
|
|
|
201 |
*
|
|
|
202 |
* $Log: not supported by cvs2svn $
|
444 |
ddelon |
203 |
* Revision 1.4 2005/09/20 17:01:22 ddelon
|
|
|
204 |
* php5 et bugs divers
|
|
|
205 |
*
|
443 |
ddelon |
206 |
* Revision 1.3 2004/11/29 15:56:23 jpm
|
|
|
207 |
* Correction bogue.
|
|
|
208 |
*
|
189 |
jpm |
209 |
* Revision 1.2 2004/11/29 15:54:16 jpm
|
|
|
210 |
* Changement de nom de variable et légère correction.
|
|
|
211 |
*
|
187 |
jpm |
212 |
* Revision 1.1 2004/11/15 17:12:46 jpm
|
|
|
213 |
* Classe de gestion d'erreur pour PHP 4.3
|
156 |
jpm |
214 |
*
|
187 |
jpm |
215 |
*
|
156 |
jpm |
216 |
* +-- Fin du code ----------------------------------------------------------------------------------------+
|
|
|
217 |
*/
|
|
|
218 |
?>
|