Download the PHP package tinywan/think-exception without Composer

On this page you can find all versions of the php package tinywan/think-exception. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package think-exception

ThinkPHP6.0 exception 异常插件

Total Downloads Daily Downloads License PHP Version Require [exception-handler]() [exception-handler]()

安装

配置

发布配置

这将自动生成 config/exception.php 配置文件。

配置异常类

日志服务 app/provider.php

日志订阅 app/event.php

基本用法

请求参数错误

以上异常抛出错误信息,如下格式:

所有返回的异常信息将以json格式返回,以上为返回简略的异常信息

所有的异常错误处理器根据配置文件 config/app.phpdebug的值来调整错误显示, 当debug值为true (表示在调试模式), 错误处理器会显示异常以及详细的函数调用栈和源代码行数来帮助调试,将返回详细的异常信息。 当debug值为false,只有错误信息会被显示以防止应用的敏感信息泄漏,将返回简略的异常信息。

返回详细的异常信息

自定义异常 Response

只支持修改body的三个字段的key值。必须保持顺序是:

使用场景

  • 每个项目有标准的统一输出,自定义返回内容
  • 前后端分离:前端要求返回的 HTTP状态码并不是 429,而是 200 或者其他
  • 响应的body不是 {"code":0,"msg":"Too Many Requests"},而是 {"error_code":200,"message":"Too Many Requests"} 等其他内容

自定义HTTP状态码

编辑 config/exception.php 文件的 status HTTP 状态码

自定义body返回内容

编辑 config/exception.php 文件的 body 的字段

默认选项是

自定义选项参考一

1、假设status HTTP 状态码设置为 200

2、假设body的数组设为为

则响应内容为

其他的可以根据自身业务自定义即可

扩展自己的 Handler

当项目需要自定义情况比较多的时候,很可能需要扩展 Handler,此时可以继承 tinywan\Handler 然后修改对应方法即可。

使用场景

  • response需要响应xml,而不是json格式,只需要覆盖buildResponse方法
  • 扩展其他Exception的响应,我只要覆盖solveExtraException
  • 要异常推送微信消息,我可以覆盖triggerNotifyEvent

自定义异常 ErrorHandler

异常通知(钉钉机器人)

自定义异常消息

Other

phpstan

vendor/bin/php-cs-fixer fix src


All versions of think-exception with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tinywan/think-exception contains the following files

Loading the files please wait ....