array Errors stack
protected $flag = false; ///< boolean True if stack is not empty
protected $html_list = "
\n"; ///< string HTML errors list pattern
protected $html_item = "%s\n"; ///< string HTML error item pattern
/**
Object constructor.
*/
public function __construct()
{
$this->code = 0;
$this->msg = '';
}
/**
Object string representation. Returns errors stack.
@return string
*/
public function __toString()
{
$res = '';
foreach ($this->errors as $msg)
{
$res .= $msg."\n";
}
return $res;
}
/**
Adds an error to stack.
@param msg string Error message
*/
public function add($msg)
{
$this->flag = true;
$this->errors[] = $msg;
}
/**
Returns the value of flag property.
@return boolean True if errors stack is not empty
*/
public function flag()
{
return $this->flag;
}
/**
Resets errors stack.
*/
public function reset()
{
$this->flag = false;
$this->errors = array();
}
/**
Returns errors property.
@return array
*/
public function getErrors()
{
return $this->errors;
}
/**
Sets list and item properties.
@param list string HTML errors list pattern
@param item string HTML error item pattern
*/
public function setHTMLFormat($list,$item)
{
$this->html_list = $list;
$this->html_item = $item;
}
/**
Returns errors stack as HTML.
@return string
*/
public function toHTML()
{
$res = '';
if ($this->flag)
{
foreach ($this->errors as $msg)
{
$res .= sprintf($this->html_item,$msg);
}
$res = sprintf($this->html_list,$res);
}
return $res;
}
}
?>