ovr / phalcon-pretty-exceptions
Phalcon的美丽异常插件
0.1.0
2016-06-14 15:05 UTC
Requires
- php: >=5.3
This package is auto-updated.
Last update: 2024-08-29 04:03:21 UTC
README
Phalcon 是一个以C扩展形式提供的Web框架,具有高性能和低资源消耗。
Beautiful Exceptions是一个用于以良好可视化的方式显示异常/错误/警告/通知的实用程序。
此实用程序不适用于生产环境。
此实用程序捕获未捕获的异常,请记得删除任何阻止此实用程序工作的try/catch。
本存储库中的代码是用PHP编写的。
自动使用
使用此实用程序的最简单方法是包含其'loader'。
require '/path/to/pretty-exceptions/loader.php';
手动包含
或者,您可以手动包含该实用程序或通过自动加载器
//Requiring the file require '/path/to/pretty-exceptions/Library.php'; //Or using an autoloader $loader = new Phalcon\Loader(); $loader->registerNamespaces(array( 'Phalcon\\Utils' => '/path/to/pretty-exceptions/Library/Phalcon/Utils/' )); $loader->register();
使用方法
监听异常
set_exception_handler(function($e) { $p = new \Phalcon\Utils\PrettyExceptions(); return $p->handle($e); });
监听用户错误/警告/通知
set_error_handler(function($errorCode, $errorMessage, $errorFile, $errorLine) { $p = new \Phalcon\Utils\PrettyExceptions(); return $p->handleError($errorCode, $errorMessage, $errorFile, $errorLine); });
选项
以下是如何配置该实用程序的方式
$p = new \Phalcon\Utils\PrettyExceptions(); //Change the base uri for static resources $p->setBaseUri('/'); //Set if the backtrace must be shown $p->showBacktrace(true); //Set whether if open the user files and show its code $p->showFiles(true); //Set whether show the complete file or just the relevant fragment $p->showFileFragment(true); /** * Set whether show human readable dump of current Phalcon application instance * Can optionally pass a Phalcon application instance as a prameter in the * constructor, or as the last parameter of PrettyExceptions::handle() and * PrettyExceptions::handleError() */ $p->showApplicationDump(true); //Change the CSS theme (default, night or minimalist) $p->setTheme('default'); //Handle the error/exception //...