pickles/classes/Error.php
Josh Sherman b53f52ac1e Changes.
git-svn-id: http://svn.cleancode.org/svn/pickles@79 4d10bc64-7434-11dc-a737-d2d0f8310089
2008-10-18 13:42:10 +00:00

100 lines
2.4 KiB
PHP
Executable file

<?php
/**
* Error Class File for PICKLES
*
* PICKLES is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* PICKLES 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with PICKLES. If not, see
* <http://www.gnu.org/licenses/>.
*
* @author Joshua John Sherman <josh@phpwithpickles.org>
* @copyright Copyright 2007, 2008 Joshua John Sherman
* @link http://phpwithpickles.org
* @license http://www.gnu.org/copyleft/lesser.html
* @package PICKLES
*/
/**
* Error handling class
*
* Handles (for the most part) all the errors and warnings that
* are encountered by the PICKLES core classes. Usage is optional
* for site level code. Errors are logged but it's up to the
* developer to interact with and/or display the errors to their
* end-users.
*/
class Error extends Object {
/**
* Private message arrays
*/
private $errors = null;
private $warnings = null;
/**
* Adds an error message
*
* @param string Error message
* @return boolean true
*/
public function addError($message) {
$this->errors[] = $message;
Logger::write('error', '[error] ' . $message);
return true;
}
/**
* Adds a warning message
*
* @param string Warning message
* @return boolean true
*/
public function addWarning($message) {
$this->warnings[] = $message;
Logger::write('error', '[warning] ' . $message);
return true;
}
/**
* Gets the stored errors
*
* @return mixed Messages in sequential order or false
*/
public function getErrors() {
return $this->errors;
}
/**
* Gets the stored warnings
*
* @return array Warning messages indexed by the order they were stored
*/
public function getWarnings() {
return $this->warnings;
}
/**
* Determines if there are any stored errors or warnings
*
* @return boolean Whether or not there are any errors or warnings.
*/
public function isError() {
if (isset($this->errors, $this->warnings)) {
return true;
}
return false;
}
}
?>