|
1 | | -<h1 align="center"> support </h1> |
| 1 | +<h1 style="text-align: center;"> support </h1> |
2 | 2 |
|
3 | | -<p align="center"> .</p> |
4 | | - |
5 | | - |
6 | | -## Installing |
| 3 | +## 安装 |
7 | 4 |
|
8 | 5 | ```shell |
9 | 6 | $ composer require zhenmu/support -vvv |
10 | 7 | ``` |
11 | 8 |
|
12 | | -## Usage |
| 9 | +## 基类创建控制器 |
| 10 | + |
| 11 | +```php |
| 12 | +./webman plugin:install zhen-mu/support |
| 13 | + |
| 14 | +or |
| 15 | + |
| 16 | +php ./vendor/zhenmu/support/src/scripts/install.php |
| 17 | +``` |
13 | 18 |
|
14 | | -TODO |
| 19 | +## 使用 |
15 | 20 |
|
16 | | -## Contributing |
| 21 | +### 控制器 |
17 | 22 |
|
18 | | -You can contribute in one of three ways: |
| 23 | +1. 通过 `./webman make:controller` 控制器生成后,继承同目录下的 `WebmanBaseController` 基类。 |
| 24 | +2. 编写接口时可通过 `$this->success($data = [], $err_code = 200, $messsage = 'success');` 返回正确数据给接口。 |
| 25 | +3. 编写接口时可通过 `$this->fail($messsage = '', $err_code = 400);` 返回错误信息给接口。 |
| 26 | +4. 在 `support/exception/Handler.php` 的 `render` 函数中,调用 `WebmanResponseTrait` 的 `$this->renderableHandle($request, $exception);` 示例如下: |
19 | 27 |
|
20 | | -1. File bug reports using the [issue tracker](https://github.com/zhenmu/support/issues). |
21 | | -2. Answer questions or fix bugs on the [issue tracker](https://github.com/zhenmu/support/issues). |
22 | | -3. Contribute new features or update the wiki. |
| 28 | +```php |
| 29 | +<?php |
23 | 30 |
|
24 | | -_The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable._ |
| 31 | +namespace support\exception; |
25 | 32 |
|
26 | | -## License |
| 33 | +use Webman\Http\Request; |
| 34 | +use Webman\Http\Response; |
| 35 | +use Throwable; |
| 36 | +use Webman\Exception\ExceptionHandler; |
| 37 | +use ZhenMu\Support\Traits\WebmanResponseTrait; |
| 38 | + |
| 39 | +/** |
| 40 | + * Class Handler |
| 41 | + * @package support\exception |
| 42 | + */ |
| 43 | +class Handler extends ExceptionHandler |
| 44 | +{ |
| 45 | + use WebmanResponseTrait; // 这里需要引入 WebmanResponseTrait |
| 46 | + |
| 47 | + public $dontReport = [ |
| 48 | + BusinessException::class, |
| 49 | + ]; |
| 50 | + |
| 51 | + public function report(Throwable $exception) |
| 52 | + { |
| 53 | + parent::report($exception); |
| 54 | + } |
| 55 | + |
| 56 | + public function render(Request $request, Throwable $exception): Response |
| 57 | + { |
| 58 | + return $this->renderableHandle($request, $exception); // 这里进行调用,做了一些错误捕捉 |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
27 | 62 |
|
28 | | -MIT |
| 63 | +**注意:头请求未声明此次请求需要返回 json 数据时,`$this->fail($message, $err_code)` 的错误码需要符合 http status_code 响应码** |
0 commit comments