Sources for file plugins/error/exceptions.php in version 4.0 Beta 1
Click on a comment to hide it. Click here to show all comments.
/**
* Project: Xnyo 4: Bubbles
* File: plugins/error/exceptions.php
*
* Version: 4.0-dev
* SVN Id: $Id: exceptions.php 5 2007-05-18 03:49:07Z bok $
* SVN URL: $HeadURL:
http://svn.syd.wholesalebroadband.com.au/xnyo/trunk/plugins/error/exceptions.php $
* Authors: Robert Amos <bok[at]odynia.org>
*
* Copyright (c) 2001-2007 Robert Amos <bok[at]odynia.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
/**
* This file includes the default exceptions that Xnyo supports during its execution.
**/
define('XNYO_EXCEPTIONS_LOADED', true);
class XnyoException extends Exception
{
protected $timestamp;
// Returns the message - clean up any html first though!
public function getCleanMessage ()
{
return preg_replace('/<(|\/)[^biu]*?>/i', '', $this->message);
}
// Returns the message stripped of html tags - for the log
public function getStrippedMessage ()
{
return preg_replace('/<[^>]+?>/', '', $this->message);
}
// Returns the timestamp
public function getTimestamp()
{
return $this->timestamp;
}
// Overrides the File / Line
public function overrideFile($file=null, $line=null)
{
if (!is_null($file))
$this->file = $file;
if (!is_null($line))
$this->line = $line;
}
}
/**
* Errors
**/
class XnyoError extends XnyoException
{
public function __construct ($message = null)
{
// default error code
$code = ERROR;
// makes the new XnyoError() call work like sprintf
if (func_num_args() > 1)
{
$args = func_get_args();
$message = call_user_func_array('sprintf', $args);
}
// set timestamp
$this->timestamp = array_sum(explode(' ', microtime()));
parent::__construct($message, $code);
}
}
/**
* Warnings
**/
class XnyoWarning extends XnyoException
{
public function __construct ($message = null)
{
$code = WARNING;
// makes the new XnyoWarning() call work like sprintf
if (func_num_args() > 1)
{
$args = func_get_args();
$message = call_user_func_array('sprintf', $args);
}
// set timestamp
$this->timestamp = array_sum(explode(' ', microtime()));
// call parent constructor
parent::__construct($message, $code);
}
}
/**
* Notices
**/
class XnyoNotice extends XnyoException
{
public function __construct ($message = null)
{
$code = NOTICE;
// makes the new XnyoWarning() call work like sprintf
if (func_num_args() > 1)
{
$args = func_get_args();
$message = call_user_func_array('sprintf', $args);
}
// set timestamp
$this->timestamp = array_sum(explode(' ', microtime()));
// call parent constructor
parent::__construct($message, $code);
}
}
/**
* Strict
**/
class XnyoStrict extends XnyoException
{
public function __construct ($message = null)
{
$code = E_STRICT;
// makes the new XnyoWarning() call work like sprintf
if (func_num_args() > 1)
{
$args = func_get_args();
$message = call_user_func_array('sprintf', $args);
}
// set timestamp
$this->timestamp = array_sum(explode(' ', microtime()));
// call parent constructor
parent::__construct($message, $code);
}
}
/**
* Client
**/
class XnyoClient extends XnyoException
{
public function __construct ($message = null)
{
$code = CLIENT;
// makes the new XnyoWarning() call work like sprintf
if (func_num_args() > 1)
{
$args = func_get_args();
$message = call_user_func_array('sprintf', $args);
}
// set timestamp
$this->timestamp = array_sum(explode(' ', microtime()));
// call parent constructor
parent::__construct($message, $code);
}
}
/**
* Debug
**/
class XnyoDebugException extends XnyoException
{
public function __construct ($msg=null)
{
$code = DEBUG;
// set timestamp
$this->timestamp = array_sum(explode(' ', microtime()));
// call parent constructor
parent::__construct($msg, $code);
// reset the file and line number to the first item in the trace
// so it doesn't think it came from the $xnyo->d() function
$t = $this->getTrace();
$this->overrideFile($t[0]['file'], $t[0]['line']);
}
}
