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 |
// +------------------------------------------------------------------------------------------------------+
|
443 |
ddelon |
24 |
// CVS : $Id: BOG_Gestionnaire_Erreur.class.php,v 1.4 2005-09-20 17:01:22 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
|
443 |
ddelon |
36 |
*@version $Revision: 1.4 $ $Date: 2005-09-20 17:01:22 $
|
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';
|
|
|
58 |
|
|
|
59 |
// Constructeur
|
|
|
60 |
function BOG_Gestionnaire_Erreur($bln_contexte, $class = '', $langue = 'fr', $txt_tete = '', $txt_pied = '', $aso_trad = array())
|
|
|
61 |
{
|
|
|
62 |
$this->ecrireContexte($bln_contexte);
|
|
|
63 |
$this->ecrireLangue($langue);
|
|
|
64 |
$this->ecrireTxtTete($txt_tete);
|
|
|
65 |
$this->ecrireTxtPied($txt_pied);
|
|
|
66 |
if (count($aso_trad) != 0) {
|
|
|
67 |
$this->ecrireTraduction($aso_trad);
|
|
|
68 |
}
|
|
|
69 |
if (! empty($class)) {
|
|
|
70 |
$this->ecrireClass($class);
|
|
|
71 |
}
|
443 |
ddelon |
72 |
|
156 |
jpm |
73 |
set_error_handler(array(&$this, 'gererErreur'));
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
// Accesseurs
|
|
|
77 |
function ecrireErreur($aso_erreur)
|
|
|
78 |
{
|
|
|
79 |
array_push($this->tab_erreurs, $aso_erreur);
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
function lireTableauErreurs()
|
|
|
83 |
{
|
|
|
84 |
return $this->tab_erreurs;
|
|
|
85 |
}
|
|
|
86 |
function lireTxtTete()
|
|
|
87 |
{
|
|
|
88 |
return $this->erreur_txt_tete;
|
|
|
89 |
}
|
|
|
90 |
function ecrireTxtTete($txt_tete)
|
|
|
91 |
{
|
|
|
92 |
$this->erreur_txt_tete = $txt_tete;
|
|
|
93 |
}
|
|
|
94 |
function lireTxtPied()
|
|
|
95 |
{
|
|
|
96 |
return $this->erreur_txt_pied;
|
|
|
97 |
}
|
|
|
98 |
function ecrireTxtPied($txt_pied)
|
|
|
99 |
{
|
|
|
100 |
$this->erreur_txt_pied = $txt_pied;
|
|
|
101 |
}
|
|
|
102 |
function lireContexte()
|
|
|
103 |
{
|
|
|
104 |
return $this->bln_contexte;
|
|
|
105 |
}
|
|
|
106 |
function ecrireContexte($bln)
|
|
|
107 |
{
|
|
|
108 |
$this->bln_contexte = $bln;
|
|
|
109 |
}
|
|
|
110 |
function lireTraduction($cle)
|
|
|
111 |
{
|
|
|
112 |
return $this->aso_trad[$cle];
|
|
|
113 |
}
|
|
|
114 |
function ecrireTraduction($tab_trad)
|
|
|
115 |
{
|
|
|
116 |
$aso_trad['niveau'] = $tab_trad[0];
|
|
|
117 |
$aso_trad['fichier'] = $tab_trad[1];
|
|
|
118 |
$aso_trad['ligne'] = $tab_trad[2];
|
|
|
119 |
$aso_trad['contexte'] = $tab_trad[3];
|
|
|
120 |
$this->aso_trad = $aso_trad;
|
|
|
121 |
}
|
|
|
122 |
function lireClass()
|
|
|
123 |
{
|
|
|
124 |
return $this->class;
|
|
|
125 |
}
|
|
|
126 |
function ecrireClass($class)
|
|
|
127 |
{
|
|
|
128 |
$this->class = $class;
|
|
|
129 |
}
|
|
|
130 |
function lireLangue()
|
|
|
131 |
{
|
|
|
132 |
return $this->langue;
|
|
|
133 |
}
|
|
|
134 |
function ecrireLangue($langue)
|
|
|
135 |
{
|
|
|
136 |
$this->langue = $langue;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
// Méthode
|
189 |
jpm |
140 |
function gererErreur($niveau, $message, $fichier, $ligne, $contexte)
|
156 |
jpm |
141 |
{
|
443 |
ddelon |
142 |
|
|
|
143 |
// Ouais bof le test, mais php5 renvoie vraiment trop de message d'erreur sur Deprecated ... et
|
|
|
144 |
// ca concerne essentiellement les classes pear !
|
|
|
145 |
|
|
|
146 |
if (!defined('E_STRICT')) {
|
|
|
147 |
define("E_STRICT", 2048);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
if ($niveau < E_STRICT) {
|
|
|
151 |
|
|
|
152 |
$aso_erreur = array();
|
|
|
153 |
$aso_erreur['niveau'] = $niveau;
|
|
|
154 |
$aso_erreur['message'] = $message;
|
|
|
155 |
$aso_erreur['fichier'] = $fichier;
|
|
|
156 |
$aso_erreur['ligne'] = $ligne;
|
|
|
157 |
if ($this->lireContexte()) {
|
|
|
158 |
$aso_erreur['contexte'] = $contexte;
|
|
|
159 |
}
|
|
|
160 |
$this->ecrireErreur($aso_erreur);
|
|
|
161 |
|
|
|
162 |
}
|
156 |
jpm |
163 |
}
|
|
|
164 |
|
|
|
165 |
function retournerErreurs()
|
|
|
166 |
{
|
|
|
167 |
$retour = '';
|
|
|
168 |
foreach($this->lireTableauErreurs() as $aso_erreur) {
|
|
|
169 |
$retour .= '<p class="'.$this->lireClass().'">'."\n";
|
|
|
170 |
$retour .= '<strong>'.$this->lireTxtTete().$aso_erreur['message'].$this->lireTxtPied().'</strong><br />'."\n";
|
|
|
171 |
$retour .= '<strong>'.$this->lireTraduction('niveau').'</strong>'.$aso_erreur['niveau'].'<br />'."\n";
|
|
|
172 |
$retour .= '<strong>'.$this->lireTraduction('fichier').'</strong>'.$aso_erreur['fichier'].'<br />'."\n";
|
|
|
173 |
$retour .= '<strong>'.$this->lireTraduction('ligne').'</strong>'.$aso_erreur['ligne'].'<br />'."\n";
|
|
|
174 |
if ($this->lireContexte()) {
|
|
|
175 |
$retour .= '<pre>'."\n";
|
|
|
176 |
$retour .= '<stong>'.$this->lireTraduction('contexte').'</stong>'.print_r($aso_erreur['contexte'], true)."\n";
|
|
|
177 |
$retour .= '</pre>'."\n";
|
|
|
178 |
}
|
|
|
179 |
$retour .= '</p>'."\n";
|
|
|
180 |
}
|
|
|
181 |
return $retour;
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
187 |
// | PIED du PROGRAMME |
|
|
|
188 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
/* +--Fin du code ----------------------------------------------------------------------------------------+
|
|
|
192 |
*
|
|
|
193 |
* $Log: not supported by cvs2svn $
|
443 |
ddelon |
194 |
* Revision 1.3 2004/11/29 15:56:23 jpm
|
|
|
195 |
* Correction bogue.
|
|
|
196 |
*
|
189 |
jpm |
197 |
* Revision 1.2 2004/11/29 15:54:16 jpm
|
|
|
198 |
* Changement de nom de variable et légère correction.
|
|
|
199 |
*
|
187 |
jpm |
200 |
* Revision 1.1 2004/11/15 17:12:46 jpm
|
|
|
201 |
* Classe de gestion d'erreur pour PHP 4.3
|
156 |
jpm |
202 |
*
|
187 |
jpm |
203 |
*
|
156 |
jpm |
204 |
* +-- Fin du code ----------------------------------------------------------------------------------------+
|
|
|
205 |
*/
|
|
|
206 |
?>
|