<?php
/**
*
* @author Benjamin Gillissen <hide@address.com>
*
* **************************************************************
Copyright (C) 2009 Benjamin Gillissen
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 at:
http://www.gnu.org/copyleft/gpl.html
* **************************************************************
*/
class error {
private $msg, $lvl, $context, $backtrace, $file, $line;
public function __construct($msg, $lvl, $context){
$this->msg = $msg;
$this->lvl = $lvl;
$this->context = $context;
$this->build_backtrace();
$this->file = $this->detectfile();
$this->line = $this->detectline();
}
public function __destruct(){
//echo "error destruction...\n";
unset($this->msg, $this->lvl, $this->context,$this->file,$this->line,$this->backtrace, $this);
}
public function __toString(){ return "[ERR2STR]".$this->file.":".$this->line."=>".$this->msg; }
public function getmsg(){ return $this->msg; }
public function getlvl(){ return $this->lvl; }
public function getcontext(){ return $this->context; }
public function getline(){ return $this->line; }
public function getfile(){ return $this->file; }
public function getbacktrace(){ return $this->backtrace; }
private function detectfile(){
if ( isset($this->backtrace[2]['file']) ){
return basename($this->backtrace[2]['file']);
} else {
return 'n-a';
}
}
private function detectline(){
if ( isset($this->backtrace[2]['line']) ){
return $this->backtrace[2]['line'];
} else {
return 'n-a';
}
}
private function build_backtrace(){
$backtrace = debug_backtrace();
foreach( $backtrace as $k => $entry ){
if ( !isset($entry['file']) ){
$bt[$k]['file'] = 'PHPBuilt-in';
$bt[$k]['line'] = 'n/a';
} else {
$bt[$k]['file'] = $entry['file'];
$bt[$k]['line'] = $entry['line'];
}
$bt[$k]['function'] = '';
if ( isset($entry['function']) ){ $bt[$k]['function'] = $entry['function']; }
if ( ! isset($entry['class']) ){
$bt[$k]['class'] = '';
$bt[$k]['type'] = '';
} else {
$bt[$k]['class'] = $entry['class'];
$bt[$k]['type'] = $entry['type'];
}
if ( ! isset($entry['args']) ){
$entry['args'] = Array();
} elseif ( ! is_array($entry['args']) ){
$entry['args'] = Array();
}
$bt[$k]['args'] = Array();
foreach($entry['args'] as $a => $arg){
$b=$arg;
if ( is_object($arg) ){ $b = 'Object('.get_class($arg).')'; }
if ( is_array($arg) ) { $b = 'Array';}
if ( strlen($b) >= 255 ){ $b = 'String('.strlen($arg).')'; } //=substr($b, 0, 27).'...'; }
$bt[$k]['args'][$a] = $b;
}
}
unset($backtrace);
$this->backtrace = $bt;
}
public function setline($line){ $this->line = $line; }
public function setfile($file){ $this->file = $file; }
}