模块

HTTP_Exception_505
继承自 HTTP_Exception
继承自 BootPHP_Exception
继承自 Exception

BootPHP 异常类。 可以使用 I18n 类翻译异常。

package
BootPHP
category
异常
author
Tinsh
copyright
© 2005-2016 Kilofox Studio

该类在 SYSPATH/classes/http/exception/505.php 第 5 行声明。

属性

public static string $error_view

错误渲染视图

string(13) "bootphp/error"

public static string $error_view_content_type

错误视图内容类型

string(9) "text/html"

public static array $php_errors

PHP 错误代码 => 人类可读的名称

array(8) (
	1 => string(11) "Fatal Error"
	256 => string(10) "User Error"
	4 => string(11) "Parse Error"
	2 => string(7) "Warning"
	512 => string(12) "User Warning"
	2048 => string(6) "Strict"
	8 => string(6) "Notice"
	4096 => string(17) "Recoverable Error"
)

protected integer $_code

HTTP 505 HTTP Version Not Supported

protected $code

protected $file

protected $line

protected $message

方法

public __construct( [ string $message = NULL , array $variables = NULL , integer $code = integer 0 ] ) (在 HTTP_Exception 中定义)

创建一个新的翻译了的异常。

throw new BootPHP_Exception('出现了可怕的错误,:user',
    array(':user' => $user));

参数

  • string $message = NULL - 状态消息,自定义显示的错误内容
  • array $variables = NULL - 翻译变量
  • integer $code = integer 0 - HTTP状态码

返回值

  • void

源代码

public function __construct($message = NULL, array $variables = NULL, $code = 0)
{
	if ($code == 0)
	{
		$code = $this->_code;
	}
	if (!isset(Response::$messages[$code]))
		throw new BootPHP_Exception('无法识别的HTTP状态码::code 。只有有效的HTTP状态码是可以接受的,请参见 RFC 2616。', array(':code' => $code));
	parent::__construct($message, $variables, $code);
}

public __toString( ) (在 BootPHP_Exception 中定义)

Magic object-to-string method.

Tags

返回值

  • string

源代码

public function __toString()
{
	return self::text($this);
}

public static handler( object $e ) (在 BootPHP_Exception 中定义)

Inline exception handler, displays the error message, source of the exception, and the stack trace of the error.

参数

  • object $e required - Exception object

Tags

返回值

  • boolean

源代码

public static function handler(Exception $e)
{
	try
	{
		// Get the exception information
		$type = get_class($e);
		$code = $e->getCode();
		$message = $e->getMessage();
		$file = $e->getFile();
		$line = $e->getLine();
		// Get the exception backtrace
		$trace = $e->getTrace();
		if ($e instanceof ErrorException)
		{
			if (isset(self::$php_errors[$code]))
			{
				// Use the human-readable error name
				$code = self::$php_errors[$code];
			}
			if (version_compare(PHP_VERSION, '5.3', '<'))
			{
				// Workaround for a bug in ErrorException::getTrace() that exists in
				// all PHP 5.2 versions. @see http://bugs.php.net/bug.php?id=45895
				for ($i = count($trace) - 1; $i > 0; --$i)
				{
					if (isset($trace[$i - 1]['args']))
					{
						// Re-position the args
						$trace[$i]['args'] = $trace[$i - 1]['args'];
						// Remove the args
						unset($trace[$i - 1]['args']);
					}
				}
			}
		}
		// Create a text version of the exception
		$error = self::text($e);
		if (is_object(BootPHP::$log))
		{
			// Add this exception to the log
			BootPHP::$log->add(Log::ERROR, $error);
			$strace = self::text($e) . "\n--\n" . $e->getTraceAsString();
			BootPHP::$log->add(Log::STRACE, $strace);
			// Make sure the logs are written
			BootPHP::$log->write();
		}
		if (!headers_sent())
		{
			// Make sure the proper http header is sent
			$http_header_status = ($e instanceof HTTP_Exception) ? $code : 500;
			header('Content-Type: ' . self::$error_view_content_type . '; charset=' . BootPHP::$charset, true, $http_header_status);
		}
		if (Request::$current !== NULL && Request::current()->is_ajax() === true)
		{
			// Just display the text of the exception
			echo "\n{$error}\n";
			exit(1);
		}
		// Start an output buffer
		ob_start();
		// Include the exception HTML
		if ($view_file = BootPHP::find_file('views', self::$error_view))
		{
			include $view_file;
		}
		else
		{
			throw new BootPHP_Exception('Error view file does not exist: views/:file', array(
			':file' => self::$error_view,
			));
		}
		// Display the contents of the output buffer
		echo ob_get_clean();
		exit(1);
	}
	catch (Exception $e)
	{
		// Clean the output buffer if one exists
		ob_get_level() and ob_clean();
		// Display the exception text
		echo self::text($e), "\n";
		// Exit with an error status
		exit(1);
	}
}

public static text( object $e ) (在 BootPHP_Exception 中定义)

Get a single line of text representing the exception:

Error [ Code ]: Message ~ File [ Line ]

参数

  • object $e required - Exception

返回值

  • string

源代码

public static function text(Exception $e)
{
	return sprintf('%s [ %s ]: %s ~ %s [ %d ]', get_class($e), $e->getCode(), strip_tags($e->getMessage()), Debug::path($e->getFile()), $e->getLine());
}

public __wakeup( ) (在 Exception 中定义)

final public getCode( ) (在 Exception 中定义)

final public getFile( ) (在 Exception 中定义)

final public getLine( ) (在 Exception 中定义)

final public getMessage( ) (在 Exception 中定义)

final public getPrevious( ) (在 Exception 中定义)

final public getTrace( ) (在 Exception 中定义)

final public getTraceAsString( ) (在 Exception 中定义)

final private __clone( ) (在 Exception 中定义)