Subversion Repositories Applications.papyrus

Rev

Rev 1558 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1558 Rev 2150
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.7 2007-08-28 14:03:33 jp_milcent Exp $
24
// CVS : $Id: BOG_Gestionnaire_Erreur.class.php,v 1.7 2007-08-28 14:03:33 jp_milcent 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.7 $ $Date: 2007-08-28 14:03:33 $
36
*@version       $Revision: 1.7 $ $Date: 2007-08-28 14:03:33 $
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
    var $active = 1;
59
    
59
    
60
    // Constructeur
60
    // Constructeur
61
    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())
62
    {
62
    {
63
        $this->ecrireContexte($bln_contexte);
63
        $this->ecrireContexte($bln_contexte);
64
        $this->ecrireLangue($langue);
64
        $this->ecrireLangue($langue);
65
        $this->ecrireTxtTete($txt_tete);
65
        $this->ecrireTxtTete($txt_tete);
66
        $this->ecrireTxtPied($txt_pied);
66
        $this->ecrireTxtPied($txt_pied);
67
        if (count($aso_trad) != 0) {
67
        if (count($aso_trad) != 0) {
68
            $this->ecrireTraduction($aso_trad);
68
            $this->ecrireTraduction($aso_trad);
69
        }
69
        }
70
        if (! empty($class)) {
70
        if (! empty($class)) {
71
            $this->ecrireClass($class);
71
            $this->ecrireClass($class);
72
        }
72
        }
73
        
73
        
74
        set_error_handler(array(&$this, 'gererErreur'));
74
        set_error_handler(array(&$this, 'gererErreur'));
75
    }
75
    }
76
    
76
    
77
    // Accesseurs
77
    // Accesseurs
78
    
78
    
79
    function setActive($active)
79
    function setActive($active)
80
    {
80
    {
81
        $this->active=$active;
81
        $this->active=$active;
82
    }
82
    }
83
    
83
    
84
    
84
    
85
    function ecrireErreur($aso_erreur)
85
    function ecrireErreur($aso_erreur)
86
    {
86
    {
87
        array_push($this->tab_erreurs, $aso_erreur);
87
        array_push($this->tab_erreurs, $aso_erreur);
88
    }
88
    }
89
    
89
    
90
    function lireTableauErreurs()
90
    function lireTableauErreurs()
91
    {
91
    {
92
        return $this->tab_erreurs;
92
        return $this->tab_erreurs;
93
    }
93
    }
94
    function lireTxtTete()
94
    function lireTxtTete()
95
    {
95
    {
96
        return $this->erreur_txt_tete;
96
        return $this->erreur_txt_tete;
97
    }
97
    }
98
    function ecrireTxtTete($txt_tete)
98
    function ecrireTxtTete($txt_tete)
99
    {
99
    {
100
        $this->erreur_txt_tete = $txt_tete;
100
        $this->erreur_txt_tete = $txt_tete;
101
    }
101
    }
102
    function lireTxtPied()
102
    function lireTxtPied()
103
    {
103
    {
104
        return $this->erreur_txt_pied;
104
        return $this->erreur_txt_pied;
105
    }
105
    }
106
    function ecrireTxtPied($txt_pied)
106
    function ecrireTxtPied($txt_pied)
107
    {
107
    {
108
        $this->erreur_txt_pied = $txt_pied;
108
        $this->erreur_txt_pied = $txt_pied;
109
    }
109
    }
110
    function lireContexte()
110
    function lireContexte()
111
    {
111
    {
112
        return $this->bln_contexte;
112
        return $this->bln_contexte;
113
    }
113
    }
114
    function ecrireContexte($bln)
114
    function ecrireContexte($bln)
115
    {
115
    {
116
        $this->bln_contexte = $bln;
116
        $this->bln_contexte = $bln;
117
    }
117
    }
118
    function lireTraduction($cle)
118
    function lireTraduction($cle)
119
    {
119
    {
120
        return $this->aso_trad[$cle];
120
        return $this->aso_trad[$cle];
121
    }
121
    }
122
    function ecrireTraduction($tab_trad)
122
    function ecrireTraduction($tab_trad)
123
    {
123
    {
124
        $aso_trad['niveau'] = $tab_trad[0];
124
        $aso_trad['niveau'] = $tab_trad[0];
125
        $aso_trad['fichier'] = $tab_trad[1];
125
        $aso_trad['fichier'] = $tab_trad[1];
126
        $aso_trad['ligne'] = $tab_trad[2];
126
        $aso_trad['ligne'] = $tab_trad[2];
127
        $aso_trad['contexte'] = $tab_trad[3];
127
        $aso_trad['contexte'] = $tab_trad[3];
128
        $this->aso_trad = $aso_trad;
128
        $this->aso_trad = $aso_trad;
129
    }
129
    }
130
    function lireClass()
130
    function lireClass()
131
    {
131
    {
132
        return $this->class;
132
        return $this->class;
133
    }
133
    }
134
    function ecrireClass($class)
134
    function ecrireClass($class)
135
    {
135
    {
136
        $this->class = $class;
136
        $this->class = $class;
137
    }
137
    }
138
    function lireLangue()
138
    function lireLangue()
139
    {
139
    {
140
        return $this->langue;
140
        return $this->langue;
141
    }
141
    }
142
    function ecrireLangue($langue)
142
    function ecrireLangue($langue)
143
    {
143
    {
144
        $this->langue = $langue;
144
        $this->langue = $langue;
145
    }
145
    }
146
    
146
    
147
    // Méthode
147
    // Méthode
148
    function gererErreur($niveau, $message, $fichier, $ligne, $contexte)
148
    function gererErreur($niveau, $message, $fichier, $ligne, $contexte)
149
    {
149
    {
150
    	if ($this->active) {
150
    	if ($this->active) {
151
	    	// 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 
152
	    	// ca concerne essentiellement les classes pear !
152
	    	// ca concerne essentiellement les classes pear !
153
	    	
153
	    	
154
	    	if (!defined('E_STRICT')) {
154
	    	if (!defined('E_STRICT')) {
155
	    		define("E_STRICT", 2048);
155
	    		define("E_STRICT", 2048);
156
	    	}
156
	    	}
157
	    	
157
	    	
158
			if ($niveau < E_STRICT) {
158
			if ($niveau < E_STRICT) {
159
	    	
159
	    	
160
		        $aso_erreur = array();
160
		        $aso_erreur = array();
161
		        $aso_erreur['niveau'] = $niveau;
161
		        $aso_erreur['niveau'] = $niveau;
162
		        $aso_erreur['message'] = $message;
162
		        $aso_erreur['message'] = $message;
163
		        $aso_erreur['fichier'] = $fichier;
163
		        $aso_erreur['fichier'] = $fichier;
164
		        $aso_erreur['ligne'] = $ligne;
164
		        $aso_erreur['ligne'] = $ligne;
165
		        if ($this->lireContexte()) {
165
		        if ($this->lireContexte()) {
166
		            $aso_erreur['contexte'] = $contexte;
166
		            $aso_erreur['contexte'] = $contexte;
167
		        }
167
		        }
168
		        $this->ecrireErreur($aso_erreur);
168
		        $this->ecrireErreur($aso_erreur);
169
		        
169
		        
170
			}
170
			}
171
    	}
171
    	}
172
    }
172
    }
173
    
173
    
174
    function retournerErreurs()
174
    function retournerErreurs()
175
    {
175
    {
176
        $contenu = '';
176
        $contenu = '';
177
        foreach($this->lireTableauErreurs() as $aso_erreur) {
177
        foreach($this->lireTableauErreurs() as $aso_erreur) {
178
            switch (PAP_DEBOGAGE_TYPE) {
178
            switch (PAP_DEBOGAGE_TYPE) {
179
            	case 'FIREBUG':
179
            	case 'FIREBUG':
180
            		$contenu .= 	"console.info(\"[Buggy] - ".
180
            		$contenu .= 	"console.info(\"[Buggy] - ".
181
						"Niveau : ".$aso_erreur['niveau']." - ".
181
						"Niveau : ".$aso_erreur['niveau']." - ".
182
						"Fichier : ".$aso_erreur['fichier']." - ".
182
						"Fichier : ".$aso_erreur['fichier']." - ".
183
						"Ligne :".$aso_erreur['ligne']." - ".
183
						"Ligne :".$aso_erreur['ligne']." - ".
184
						"Message : ".$aso_erreur['message']." - ".
184
						"Message : ".$aso_erreur['message']." - ".
185
						"\");\n";
185
						"\");\n";
186
					break;
186
					break;
187
            	case 'HTML':
187
            	case 'HTML':
188
            	default:
188
            	default:
189
	            	$contenu .= '<p class="'.$this->lireClass().'">'."\n";
189
	            	$contenu .= '<p class="'.$this->lireClass().'">'."\n";
190
		            $contenu .= '<strong>'.$this->lireTxtTete().$aso_erreur['message'].$this->lireTxtPied().'</strong><br />'."\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";
191
		            $contenu .= '<strong>'.$this->lireTraduction('niveau').'</strong>'.$aso_erreur['niveau'].'<br />'."\n";
192
		            $contenu .= '<strong>'.$this->lireTraduction('fichier').'</strong>'.$aso_erreur['fichier'].'<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";
193
		            $contenu .= '<strong>'.$this->lireTraduction('ligne').'</strong>'.$aso_erreur['ligne'].'<br />'."\n";
194
		            if ($this->lireContexte()) {
194
		            if ($this->lireContexte()) {
195
		                $contenu .= '<pre>'."\n";
195
		                $contenu .= '<pre>'."\n";
196
		                $contenu .= '<stong>'.$this->lireTraduction('contexte').'</stong>'.print_r($aso_erreur['contexte'], true)."\n";
196
		                $contenu .= '<stong>'.$this->lireTraduction('contexte').'</stong>'.print_r($aso_erreur['contexte'], true)."\n";
197
		                $contenu .= '</pre>'."\n";
197
		                $contenu .= '</pre>'."\n";
198
		            }
198
		            }
199
	            	$contenu .= '</p>'."\n";
199
	            	$contenu .= '</p>'."\n";
200
            }
200
            }
201
            
201
            
202
        }
202
        }
203
        switch (PAP_DEBOGAGE_TYPE) {
203
        switch (PAP_DEBOGAGE_TYPE) {
204
        	case 'FIREBUG':
204
        	case 'FIREBUG':
205
        		$retour = '<script type="text/javascript">'."\n".$contenu.'</script>'."\n";
205
        		$retour = '<script type="text/javascript">'."\n".$contenu.'</script>'."\n";
206
				break;
206
				break;
207
        	case 'HTML':
207
        	case 'HTML':
208
        	default:
208
        	default:
209
            	$retour = $contenu;
209
            	$retour = $contenu;
210
		}
210
		}
211
        return $retour;
211
        return $retour;
212
    }
212
    }
213
}
213
}
214
 
214
 
215
 
215
 
216
// +------------------------------------------------------------------------------------------------------+
216
// +------------------------------------------------------------------------------------------------------+
217
// |                                            PIED du PROGRAMME                                         |
217
// |                                            PIED du PROGRAMME                                         |
218
// +------------------------------------------------------------------------------------------------------+
218
// +------------------------------------------------------------------------------------------------------+
219
 
219
 
220
 
220
 
221
/* +--Fin du code ----------------------------------------------------------------------------------------+
221
/* +--Fin du code ----------------------------------------------------------------------------------------+
222
*
222
*
223
* $Log: not supported by cvs2svn $
223
* $Log: BOG_Gestionnaire_Erreur.class.php,v $
-
 
224
* Revision 1.7  2007-08-28 14:03:33  jp_milcent
-
 
225
* Ajout du type de script utilisé côté client.
-
 
226
*
224
* Revision 1.6  2007-03-01 11:07:43  jp_milcent
227
* Revision 1.6  2007-03-01 11:07:43  jp_milcent
225
* Gestion de deux types de débogage : html ou firebug.
228
* Gestion de deux types de débogage : html ou firebug.
226
*
229
*
227
* Revision 1.5  2005/09/20 20:25:39  ddelon
230
* Revision 1.5  2005/09/20 20:25:39  ddelon
228
* php5 et bugs divers
231
* php5 et bugs divers
229
*
232
*
230
* Revision 1.4  2005/09/20 17:01:22  ddelon
233
* Revision 1.4  2005/09/20 17:01:22  ddelon
231
* php5 et bugs divers
234
* php5 et bugs divers
232
*
235
*
233
* Revision 1.3  2004/11/29 15:56:23  jpm
236
* Revision 1.3  2004/11/29 15:56:23  jpm
234
* Correction bogue.
237
* Correction bogue.
235
*
238
*
236
* Revision 1.2  2004/11/29 15:54:16  jpm
239
* Revision 1.2  2004/11/29 15:54:16  jpm
237
* Changement de nom de variable et légère correction.
240
* Changement de nom de variable et légère correction.
238
*
241
*
239
* Revision 1.1  2004/11/15 17:12:46  jpm
242
* Revision 1.1  2004/11/15 17:12:46  jpm
240
* Classe de gestion d'erreur pour PHP 4.3
243
* Classe de gestion d'erreur pour PHP 4.3
241
*
244
*
242
*
245
*
243
* +-- Fin du code ----------------------------------------------------------------------------------------+
246
* +-- Fin du code ----------------------------------------------------------------------------------------+
244
*/
247
*/
245
?>
248
?>