<?php
/*
Message.php, provides functions for error and confirmation logging and
display
Copyright (C) 2003 Arend van Beelen, Auton Rijnsburg
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For any questions, comments or whatever, you may mail me at: hide@address.com
*/
require_once('Output.php');
/**
* @brief Class used for logging and displaying confirmations and errors.
*
* Use the static functions error() and confirm() to report errors and
* confirmations. You can then add a MessagesWidget somewhere in your
* GUI which will show them.
*
* @sa MessagesWidget
*/
class Messages
{
private static function instance()
{
if(self::$instance == null)
{
self::$instance = new Messages();
}
return self::$instance;
}
private function __construct()
{
$this->errors = array();
$this->confirmations = array();
}
/**
* Adds an error to the errors log.
*/
public static function error($error)
{
$messages = self::instance();
$messages->errors[] = $error;
}
/**
* Adds a confirmation to the confirmation log.
*/
public static function confirm($confirm)
{
$messages = self::instance();
$messages->confirmations[] = $confirm;
}
/**
* @internal
*/
public static function show()
{
$messages = self::instance();
if(sizeof($messages->errors) == 0 && sizeof($messages->confirmations) == 0)
{
return;
}
Output::write('<messageswidget>');
foreach($messages->errors as $message)
{
Output::write(" <line><label class=\"error\">$message</label></line>");
}
foreach($messages->confirmations as $message)
{
Output::write(" <line><label class=\"confirm\">$message</label></line>");
}
Output::write('</messageswidget>');
}
private static $instance = null;
private $errors;
private $confirmations;
}
?>