Файл: adultscript-2.0.3-pro/files/libraries/framework/error.php
Строк: 240
<?php
defined('_VALID') or die('Restricted Access!');
if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
define('E_USER_DEPRECATED', 16384);
}
class VError
{
public static $php_errors = array(
E_ERROR => 'Fatal Error',
E_USER_ERROR => 'User Error',
E_PARSE => 'Parse Error',
E_CORE_ERROR => 'Core Error',
E_COMPILE_ERROR => 'Compile Error',
);
public static $php_warnings = array(
E_COMPILE_WARNING => 'Compile Warning',
E_CORE_WARNING => 'Startup Warning',
E_WARNING => 'Warning',
E_USER_WARNING => 'User Warning',
E_STRICT => 'Strict',
E_NOTICE => 'Notice',
E_RECOVERABLE_ERROR => 'Recoverable Error',
E_DEPRECATED => 'Deprecated',
E_USER_DEPRECATED => 'User Deprecated',
);
public static $shutdown_errors = array(E_PARSE, E_ERROR, E_USER_ERROR, E_COMPILE_ERROR);
public static function exception_handler($e)
{
try {
$type = get_class($e);
$code = $e->getCode();
$message = $e->getMessage();
$file = $e->getFile();
$line = $e->getLine();
$error = self::exception_text($e);
// we might want to handle logging here ... good idea :-)
// code here
if (PHP_SAPI === 'cli') {
echo "n{$error}n";
return TRUE;
}
// Get the exception backtrace
$trace = $e->getTrace();
if ($e instanceof ErrorException) {
if (isset(self::$php_errors[$code])) {
$code = self::$php_errors[$code];
}
if (isset(self::$php_warnings[$code])) {
$code = self::$php_warnings[$code];
}
if (version_compare(PHP_VERSION, '5.3', '<')) {
$count = count($trace);
for ($i = $count - 1; $i > 0; --$i) {
$trace[$i]['args'] = $trace[$i - 1]['args'];
}
}
}
if (!headers_sent()) {
header('Content-Type: text/html; charset=utf8', TRUE, 500);
}
ob_start();
// lets load our error view here
require BASE_DIR.'/templates/error_template.php';
echo ob_get_clean();
return TRUE;
} catch (Exception $e) {
ob_get_level() and ob_clean();
echo self::exception_text($e),"n";
}
}
public static function shutdown_handler()
{
// this is like the worst pain in the ass you could ever have :-) its a adult script btw :-)
// just in case you have to say something about my words :PPPP
if (!VF::$running) {
return;
}
if ($error = error_get_last() && isset($error) &&
in_array($error['type'], self::$shutdown_errors)) {
ob_get_level() and ob_clean();
VError::exception_handler(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
exit(1);
}
}
public static function error_handler($code, $error, $file=NULL, $line=NULL)
{
if (error_reporting() && $code !== 0) {
throw new ErrorException($error, $code, 0, $file, $line);
}
return TRUE;
}
public static function exception_text(Exception $e)
{
return sprintf('%s [ %s ]: %s ~ %s [ %d ]',
get_class($e), $e->getCode(), strip_tags($e->getMessage()), $e->getFile(), $e->getLine());
}
// from Kohana 3.0.8 ... hope nobody minds this :-)
public static function trace(array $trace = NULL)
{
if ($trace === NULL)
{
// Start a new trace
$trace = debug_backtrace();
}
// Non-standard function calls
$statements = array('include', 'include_once', 'require', 'require_once');
$output = array();
foreach ($trace as $step)
{
if ( ! isset($step['function']))
{
// Invalid trace step
continue;
}
if (isset($step['file']) AND isset($step['line']))
{
// Include the source of this step
$source = self::source($step['file'], $step['line']);
}
if (isset($step['file']))
{
$file = $step['file'];
if (isset($step['line']))
{
$line = $step['line'];
}
}
// function()
$function = $step['function'];
if (in_array($step['function'], $statements))
{
if (empty($step['args']))
{
// No arguments
$args = array();
}
else
{
// Sanitize the file path
$args = array($step['args'][0]);
}
}
elseif (isset($step['args']))
{
if ( ! function_exists($step['function']) OR strpos($step['function'], '{closure}') !== FALSE)
{
// Introspection on closures or language constructs in a stack trace is impossible
$params = NULL;
}
else
{
if (isset($step['class']))
{
if (method_exists($step['class'], $step['function']))
{
$reflection = new ReflectionMethod($step['class'], $step['function']);
}
else
{
$reflection = new ReflectionMethod($step['class'], '__call');
}
}
else
{
$reflection = new ReflectionFunction($step['function']);
}
// Get the function parameters
$params = $reflection->getParameters();
}
$args = array();
foreach ($step['args'] as $i => $arg)
{
if (isset($params[$i]))
{
// Assign the argument by the parameter name
$args[$params[$i]->name] = $arg;
}
else
{
// Assign the argument by number
$args[$i] = $arg;
}
}
}
if (isset($step['class']))
{
// Class->method() or Class::method()
$function = $step['class'].$step['type'].$step['function'];
}
$output[] = array(
'function' => $function,
'args' => isset($args) ? $args : NULL,
'file' => isset($file) ? $file : NULL,
'line' => isset($line) ? $line : NULL,
'source' => isset($source) ? $source : NULL,
);
unset($function, $args, $file, $line, $source);
}
return $output;
}
public static function source($file, $line_number, $padding = 5)
{
if ( ! $file OR ! is_readable($file))
{
// Continuing will cause errors
return FALSE;
}
// Open the file and set the line position
$file = fopen($file, 'r');
$line = 0;
// Set the reading range
$range = array('start' => $line_number - $padding, 'end' => $line_number + $padding);
// Set the zero-padding amount for line numbers
$format = '% '.strlen($range['end']).'d';
$source = '';
while (($row = fgets($file)) !== FALSE)
{
// Increment the line number
if (++$line > $range['end'])
break;
if ($line >= $range['start'])
{
// Make the row safe for output
$row = htmlspecialchars($row, ENT_NOQUOTES, 'UTF-8');
// Trim whitespace and sanitize the row
$row = '<span class="number">'.sprintf($format, $line).'</span> '.$row;
if ($line === $line_number)
{
// Apply highlighting to this row
$row = '<span class="line highlight">'.$row.'</span>';
}
else
{
$row = '<span class="line">'.$row.'</span>';
}
// Add to the captured source
$source .= $row;
}
}
// Close the file
fclose($file);
return '<pre class="source"><code>'.$source.'</code></pre>';
}
}