Subversion Repositories Applications.papyrus

Rev

Rev 443 | Rev 1238 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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