Download the PHP package xeewill/webman-exception without Composer

On this page you can find all versions of the php package xeewill/webman-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 webman-exception

webman exception handler 异常插件

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

安装

配置

config/exception.php

多应用模式时,你可以为每个应用单独配置异常处理类,参见多应用

基本用法

请求参数错误

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

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

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

返回详细的异常信息

增加异常扩展响应数据

将会在响应的 data 增加自义定的扩展响应参数

增加data的返回详细的异常信息

如何自定义一个自己的异常类

编写异常类

假设自定义一个:405 Method Not Allowed(表示:请求行中指定的请求方法不能被用于请求相应的资源)

自定义异常类只需要继承Tinywan\ExceptionHandler\Exception\BaseException类即可

使用异常类

使用postman请求截图

已支持插件异常类

内置异常类

更多:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status

自定义异常 Response

使用场景

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

自定义HTTP状态码

编辑 config/plugin/tinywan/exception-handler/app.php 文件的 status HTTP 状态码

自定义body返回内容

编辑 config/plugin/tinywan/exception-handler/app.php 文件的 body 的字段

默认选项是

自定义选项参考一

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

2、假设body的数组设为为

则响应内容为

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

扩展自己的 Handler

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

使用场景

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

自定义异常 ErrorHandler

异常通知(钉钉机器人)

Other

phpstan

vendor/bin/php-cs-fixer fix src


All versions of webman-exception with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
workerman/webman-framework Version ^1.5
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 xeewill/webman-exception contains the following files

Loading the files please wait ....