\n%s\n";
/** @var string HTML error item pattern */
protected $html_item = "
%s\n";
/**
* 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 string $msg Error message
*/
public function add($msg)
{
$this->flag = true;
$this->errors[] = $msg;
}
/**
* Returns the value of flag property. True if errors stack is not empty
*
* @return boolean
*/
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 string $list HTML errors list pattern
* @param string $item 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;
}
}