Skip to content

Commit 1bba105

Browse files
committed
chore: 更新文档
1 parent 41eced3 commit 1bba105

File tree

4 files changed

+70
-17
lines changed

4 files changed

+70
-17
lines changed

README.md

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,63 @@
1-
<h1 align="center"> support </h1>
1+
<h1 style="text-align: center;"> support </h1>
22

3-
<p align="center"> .</p>
4-
5-
6-
## Installing
3+
## 安装
74

85
```shell
96
$ composer require zhenmu/support -vvv
107
```
118

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+
```
1318

14-
TODO
19+
## 使用
1520

16-
## Contributing
21+
### 控制器
1722

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);` 示例如下:
1927

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
2330

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;
2532

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+
```
2762

28-
MIT
63+
**注意:头请求未声明此次请求需要返回 json 数据时,`$this->fail($message, $err_code)` 的错误码需要符合 http status_code 响应码**

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
"name": "zhenmu/support",
33
"description": "Package description here.",
44
"license": "MIT",
5+
"support": {
6+
"issues": "https://github.com/mouyong/php-support/issues",
7+
"source": "https://github.com/mouyong/php-support"
8+
},
59
"authors": [
610
{
711
"name": "mouyong",
8-
"email": "my242551325@gmail.com"
9-
}
12+
"email": "my24251325@gmail.com",
13+
"homepage": "https://github.com/mouyong",
14+
"role": "Creator"
15+
},
1016
],
1117
"require": {
1218
"ext-json": "*",

src/scripts/install.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require_once __DIR__.'/../../../../autoload.php';
5+
6+
\ZhenMu\SupportInstall::install();

src/scripts/uninstall.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require_once __DIR__.'/../../../../autoload.php';
5+
6+
\ZhenMu\Support\Install::uninstall();

0 commit comments

Comments
 (0)