<?php
/**
* This class implement a stack of error mesages.
* <br>Last update: September 20, 2009
* <br>License: BSD
* <br>Author: Marcelo Entraigas <marcelo [at] entraigas.com.ar>
*/
class Error {
/**
* Set the error message
*
* @param string $Error
*/
function error($error='', $exit=false){
if (!isset($_SESSION['error']) || !is_array($_SESSION['error']))
$_SESSION['error'] = array();
if(!empty($error))
$_SESSION['error'][] = $error;
if($exit){
echo $this->getErrors();
exit;
}
}
/**
* Flush all errors
*/
function flushErrors() {
$_SESSION['error'] = array();
}
/**
* Returns a string error message
*
* @return string
*/
function getErrors() {
if ($this->countErrors()==0)
return '';
$html = implode("<br>", $_SESSION['error']);
$this->flushErrors();
return "<!--Errors--->\n<font face=arial size=3>" . $html . "</font>\n";
}
/**
* Coount the registered errors
*
* @return integer
*/
function countErrors() {
return count($_SESSION['error']);
}
}
?>
|