brenno-duarte/prettyexception 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

brenno-duarte/prettyexception

Composer 安装命令:

composer require brenno-duarte/prettyexception

包简介

PrettyException is a component that helps to manipulate the Whoops component.

README 文档

README

PrettyException is a component that helps to manipulate the Whoops component.

How to use

use PrettyException\PrettyException;

$exception = new PrettyException();

You can return the error using:

  • inPretty: returns with the Whoops screen
  • inJson: returns the exception in JSON
  • inText: returns the exception in text
  • inXml: returns the exception in XML

Then use the run method.

$exception = new PrettyException();
$exception->inPretty()->run();

Customizing the exception screen

It is possible to make some customizations on the exception screen.

setTitle: Sets the title for the error page.

$exception->setTitle('New Exception');

table: Adds a key=>value table of arbitrary data, labeled by $label, to the output. Useful where you want to display contextual data along with the error, about your application or project.

$exception->table('New Exception', [
    'exc' => 'test',
    'exc2' => 10
]);

tableCallback: Similar to PrettyPageHandler::addDataTable, but accepts a callable that will be called only when rendering an exception. This allows you to gather additional data that may not be available very early in the process.

$exception->tableCallback('New Exception Callback', function(\Whoops\Exception\Inspector $inspector) {
    $data = array();
    $exception = $inspector->getException();
    if ($exception instanceof SomeSpecificException) {
        $data['Important exception data'] = $exception->getSomeSpecificData();
    }
    $data['Exception class'] = get_class($exception);
    $data['Exception code'] = $exception->getCode();
    return $data;
});

closeTableAndRun: Closes the table and executes the exception. Optionally, you can add a comment.

$exception->closeTableAndRun($comment);

Running exception in other formats

In some cases like AJAX requests or using the command line, it is possible to display exceptions using runIfAjax and runIfCli.

runIfAjax will be executed if there are any AJAX requests and returned in JSON. Otherwise, the standard exception screen will be displayed.

runIfCli will only be run from the PHP command line.

$run->runIfAjax('Exception in AJAX');
$run->runIfCli('Exception in CLI');

License

MIT

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固