- <?php
- /*
- * Lokorin.com
- * Copyright 2004-2006
- * Licensed under the GNU LGPL. See COPYING for full terms.
- */
- /**
- * A library that contains everything that is connected to errors.
- * @author Andreas Launila
- * @version $Revision: 1.10 $
- * @package com.lokorin.lokorin.lib
- * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
- */
-
- /**
- * For access to common constants and functions.
- */
- require_once('common.php');
-
- /**
- * Inserts and error into the error table in the database.
- * @param string $message The error message.
- * @param string $url The URL where the error occured, the current url is
- * used by default.
- * @access public
- */
- function insertError($message, $url='') {
- global $db;
-
- if(DEBUG_MODE_ON) {
- echo '<b>'.htmlspecialchars($message).'</b>';
- }
-
- if($url == '') {
- doInclude('lib_util');
- $url = getCurrentUrl();
- }
- $vars = array(
- 'message' => $message,
- 'url' => $url,
- 'ip' => $_SERVER['REMOTE_ADDR'],
- 'browser' => $_SERVER['HTTP_USER_AGENT'],
- 'timestamp' => time());
-
- $db->queryInsert(TABLE_ERRORS, $vars);
- }
-
-
- /**
- * Logs an exception, providing information about the current state. The script
- * then continues on.
- * @param string $exception The exception that should be logged.
- * @access public
- */
- function logException(Exception $exception) {
- insertError('Exception: [File: '.$exception->getFile().', Line: '.
- $exception->getLine().', Message: '.$exception->getMessage().']');
- }
-
- /**
- * Logs a fatal exception, providing information about the current state.
- * The exception is fatal so the script immidiatly dies after logging it.
- * @param string $exception The exception that should be logged.
- * @access public
- */
- function logFatalException(Exception $exception) {
- insertError('Exception: [File: '.$exception->getFile().', Line: '.
- $exception->getLine().', Message: '.$exception->getMessage().']');
- die('A fatal error has been detected, the error has been logged and the '.
- 'webmaster will be notified. Sorry for any inconvenience this ' .
- 'error may have caused you.');
- }
-
- /**
- * An exception used when an element that was searched for could not be found.
- * @author Andreas Launila
- * @package com.lokorin.lokorin.lib
- */
- class NoSuchElementException extends Exception {}
-
- /**
- * An exception used when an error occurs while performing an IO operation.
- * @author Andreas Launila
- * @package com.lokorin.lokorin.lib
- */
- class IOException extends Exception {}
-
- /**
- * An exception used when an error occurs while performing an IO operation
- * because of that a file was not found.
- * @author Andreas Launila
- * @package com.lokorin.lokorin.lib
- */
- class FileNotFoundException extends IOException {}
-
- /**
- * An exception used when an error occurs as a result of invalid input
- * arguments to a function.
- * @author Andreas Launila
- * @package com.lokorin.lokorin.lib
- */
- class IllegalArgumentException extends Exception {}
-
- /**
- * An exception used when an error occurs as a result of invalid state.
- * @author Andreas Launila
- * @package com.lokorin.lokorin.lib
- */
- class IllegalStateException extends Exception {}
-
- /**
- * An exception used when an error occurs as a result of an invalid url being
- * requested.
- * @author Andreas Launila
- * @package com.lokorin.lokorin.lib
- */
- class UrlNotFoundException extends Exception {}
-
- ?>