diff options
Diffstat (limited to 'lib/class/error.class.php')
-rw-r--r-- | lib/class/error.class.php | 142 |
1 files changed, 65 insertions, 77 deletions
diff --git a/lib/class/error.class.php b/lib/class/error.class.php index 013a2e08..bc839bdb 100644 --- a/lib/class/error.class.php +++ b/lib/class/error.class.php @@ -1,92 +1,80 @@ <?php -/* - - Copyright (c) 2001 - 2006 Ampache.org - All rights reserved. - - 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. - -*/ - -/*! - @header Error handler requires error_results() function - -*/ -class Error { - - //Basic Componets - var $error_state=0; - - /* Generated values */ - var $errors = array(); - - /*! - @function error - @discussion this is the constructor for the error class - */ - function Error() { - - return true; - - } //constructor +/** + * Error class + * This is the baic error class, its better now that we can use php5 + * hello static functions and variables + */ +class Error { + + public static $state = false; // set to one when an error occurs + public static $errors = array(); // Errors array key'd array with errors that have occured + + /** + * __constructor + * This does nothing... amazing isn't it! + */ + private function __construct() { + + // Rien a faire + + } // __construct + + /** + * add + * This is a public static function it adds a new error message to the array + * It can optionally clobber rather then adding to the error message + */ + public static function add($name,$message,$clobber=0) { + + // Make sure its set first + if (!isset(Error::$errors[$name])) { + Error::$errors[$name] = $message; + Error::$state = 1; + return true; + } - /*! - @function add_error - @discussion adds an error to the static array stored in - error_results() - */ - function add_error($name,$description) { + // They want us to clobber it + if ($clobber) { + Error::$state = 1; + Error::$errors[$name] = $message; + return true; + } - $array = array($name=>$description); + // They want us to append the error, add a BR\n and then the message + else { + Error::$state = 1; + Error::$errors[$name] .= "<br />\n" . $message; + return true; + } - error_results($array,1); - $this->error_state = 1; - return true; - - } // add_error + } // add + /** + * get + * This returns an error by name + */ + public static function get($name) { - /*! - @function has_error - @discussion returns true if the name given has an error, - false if it doesn't - */ - function has_error($name) { + if (!isset(Error::$errors[$name])) { return ''; } - $results = error_results($name); + return Error::$errors[$name]; - if (!empty($results)) { - return true; - } + } // get - return false; + /** + * display + * This prints the error out with a standard Error class span + * Ben Goska: Renamed from print to display, print is reserved + */ + public static function display($name) { - } // has_error + // Be smart about this, if no error don't print + if (!isset(Error::$errors[$name])) { return ''; } - /*! - @function print_error - @discussion prints out the error for a name if it exists - */ - function print_error($name) { + echo '<span class="error">' . Error::$errors[$name] . '</span>'; - if ($this->has_error($name)) { - echo "<div class=\"fatalerror\">" . error_results($name) . "</div>\n"; - } + } // display - } // print_error -} //end error class -?> +} // Error |