Subversion Repositories Applications.framework

Rev

Rev 369 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 369 Rev 497
Line 9... Line 9...
9
 * @author		Aurélien PERONNET <aurelien@tela-botanica.org>
9
 * @author		Aurélien PERONNET <aurelien@tela-botanica.org>
10
 * @author		Jean-Pascal MILCENT <jmp@tela-botanica.org>
10
 * @author		Jean-Pascal MILCENT <jmp@tela-botanica.org>
11
 * @copyright	Copyright (c) 2009, Tela Botanica (accueil@tela-botanica.org)
11
 * @copyright	Copyright (c) 2009, Tela Botanica (accueil@tela-botanica.org)
12
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
13
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
14
 * @version	$Id: GestionnaireException.php 369 2011-10-03 12:47:17Z jpm $$
14
 * @version	$Id: GestionnaireException.php 497 2019-09-17 09:49:05Z killian $$
15
 * @link		/doc/framework/
15
 * @link		/doc/framework/
16
 *
16
 *
17
 */
17
 */
18
class GestionnaireException {
18
class GestionnaireException {
Line 86... Line 86...
86
	/**
86
	/**
87
	 * Fonction de gestion des exceptions, remplace le handler par défaut.
87
	 * Fonction de gestion des exceptions, remplace le handler par défaut.
88
	 * Si une boucle génère de multiple exception (ou erreur) identique une seule sera stockée.
88
	 * Si une boucle génère de multiple exception (ou erreur) identique une seule sera stockée.
89
	 * @param Exception $e l'exception à traiter
89
	 * @param Exception $e l'exception à traiter
90
	 */
90
	 */
91
	public static function gererException(Exception $e) {
91
	public static function gererException(Throwable $e) {
92
		$cle = hash('md5', $e->getMessage().'-'.$e->getFile().'-'.$e->getLine());
92
		$cle = hash('md5', $e->getMessage().'-'.$e->getFile().'-'.$e->getLine());
93
		if (!isset(self::$exceptions[$cle])) {
93
		if (!isset(self::$exceptions[$cle])) {
94
			self::$exceptions[$cle] = $e;
94
			self::$exceptions[$cle] = $e;
95
			self::loggerException($e);
95
			self::loggerException($e);
96
		}
96
		}
Line 171... Line 171...
171
 
171
 
172
	/**
172
	/**
173
	 * Logue une exception donnée sous une forme lisible si self::logger vaut true.
173
	 * Logue une exception donnée sous une forme lisible si self::logger vaut true.
174
	 * @param Exception	$e l'exception à logger
174
	 * @param Exception	$e l'exception à logger
175
	 */
175
	 */
176
	private static function loggerException(Exception $e) {
176
	private static function loggerException(Throwable $e) {
177
		if (self::$logger) {
177
		if (self::$logger) {
178
			$message = self::formaterExceptionTxt($e);
178
			$message = self::formaterExceptionTxt($e);
179
			Log::ajouterEntree('erreurs', $message);
179
			Log::ajouterEntree('erreurs', $message);
180
		}
180
		}
Line 186... Line 186...
186
	 * le débug est lancée.
186
	 * le débug est lancée.
187
	 * TODO : faire en sorte d'afficher le fichier et la ligne où le débug est lancé.
187
	 * TODO : faire en sorte d'afficher le fichier et la ligne où le débug est lancé.
188
	 * @since 0.3
188
	 * @since 0.3
189
	 * @param Exception l'exception à formater.
189
	 * @param Exception l'exception à formater.
190
	 */
190
	 */
191
	public static function formaterExceptionDebug(Exception $e) {
191
	public static function formaterExceptionDebug(Throwable $e) {
192
		$txt = '';
192
		$txt = '';
193
		if ($e->getSeverity() == E_USER_NOTICE) {
193
		if ($e->getSeverity() == E_USER_NOTICE) {
194
			$txt = $e->getMessage();
194
			$txt = $e->getMessage();
195
		} else {
195
		} else {
196
			$txt = self::formaterExceptionTxt($e);
196
			$txt = self::formaterExceptionTxt($e);
Line 201... Line 201...
201
	/**
201
	/**
202
	 * Formate en texte une exception passée en paramètre.
202
	 * Formate en texte une exception passée en paramètre.
203
	 * @since 0.3
203
	 * @since 0.3
204
	 * @param Exception l'exception à formater.
204
	 * @param Exception l'exception à formater.
205
	 */
205
	 */
206
	public static function formaterExceptionTxt(Exception $e) {
206
	public static function formaterExceptionTxt(Throwable $e) {
207
		$message = '';
207
		$message = '';
208
		$message .= $e->getMessage()."\n";
208
		$message .= $e->getMessage()."\n";
209
		$message .= 'Fichier : '.$e->getFile()."\n";
209
		$message .= 'Fichier : '.$e->getFile()."\n";
210
		$message .= 'Ligne : '.$e->getLine()."\n";
210
		$message .= 'Ligne : '.$e->getLine()."\n";
211
		if (self::getContexte()) {
211
		if (self::getContexte()) {
Line 218... Line 218...
218
	/**
218
	/**
219
	 * Formate en (X)HTML une exception passée en paramètre.
219
	 * Formate en (X)HTML une exception passée en paramètre.
220
	 * @since 0.3
220
	 * @since 0.3
221
	 * @param Exception l'exception à formater.
221
	 * @param Exception l'exception à formater.
222
	 */
222
	 */
223
	public static function formaterExceptionXhtml(Exception $e) {
223
	public static function formaterExceptionXhtml(Throwable $e) {
224
		$message = '';
224
		$message = '';
225
		$message .= '<div class="debogage">'."\n";
225
		$message .= '<div class="debogage">'."\n";
226
		$message .= $e->getMessage()."\n";
226
		$message .= $e->getMessage()."\n";
227
		$message .= '<span class="debogage_fichier">'.'Fichier : '.$e->getFile().'</span>'."\n";
227
		$message .= '<span class="debogage_fichier">'.'Fichier : '.$e->getFile().'</span>'."\n";
228
		$message .= '<span class="debogage_ligne">'.'Ligne : '.$e->getLine().'</span>'."\n";
228
		$message .= '<span class="debogage_ligne">'.'Ligne : '.$e->getLine().'</span>'."\n";
Line 245... Line 245...
245
			echo self::getExceptionsFormatees();
245
			echo self::getExceptionsFormatees();
246
		}
246
		}
247
	}
247
	}
Line 248... Line 248...
248
 
248
 
249
}
-
 
250
?>
249
}
-
 
250
?>