softius / exceptionist
PHP 5.3的异常处理器
0.3
2013-06-05 07:39 UTC
This package is auto-updated.
Last update: 2024-09-14 04:21:28 UTC
README
Exceptionist为PHP 5.3+提供异常处理器。根据应用环境,您可以选择显示带堆栈跟踪的详细错误报告或仅提及发生异常的迷你报告。
安装
Exceptionist可在Packagist上找到。您只需在项目的composer.json
文件中添加以下行:
{ "require": { "softius/exceptionist": "0.1" } }
并通过composer安装
php composer.phar install
然后,您需要设置GenericExceptionHandler
。建议您在脚本中尽早设置以下内容:
set_exception_handler(array(new \Exceptionist\GenericExceptionHandler(array('project_root' => 'project_root_dir')), 'handle'));
配置
GenericExceptionHandler
接受一个配置数组,包含以下选项:
project_root
:定义项目根目录,默认为null
。template_script
:要使用的模板的完整路径。以下内置模板可用:\Exceptionist\ExceptionReporter::TEMPLATE_DETAILED
code_block_length
:每个代码块中显示的行数,默认为10。
工作原理
ExceptionHandler
使用ExceptionReporter
类生成并显示异常报告。这仅发生在抛出异常且未在try/catch块中捕获的情况下。模板在templates
目录中可用,可以根据需要复制、修改和调整。