heartide / response
基于Hyperf2.0扩展Response
Installs: 23
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 1
Open Issues: 0
pkg:composer/heartide/response
Requires
- hyperf/http-message: ~2.0.0
- hyperf/http-server: ~2.0.0
- hyperf/utils: ~2.0.0
- psr/container: ^1.0
- psr/http-message: ~1.0
This package is auto-updated.
Last update: 2025-10-24 13:57:48 UTC
README
- 基于Hyperf2.0中的Response扩展
运行环境
确保操作环境满足以下要求:
- PHP >= 7.2
- Swoole PHP extension >= 4.4,and Disabled
Short Name - OpenSSL PHP extension
- JSON PHP extension
- PDO PHP extension (If you need to use MySQL Client)
- Redis PHP extension (If you need to use Redis Client)
- Protobuf PHP extension (If you need to use gRPC Server of Client)
安装
- 引入组件
$ compsoer require "heartide/response"
使用
- 文件
app/Controller/AbstractController.php
- 删除
use Hyperf\HttpServer\Contract\ResponseInterface;
注入
use Heartide\Response\Response; use Psr\Container\ContainerInterface; /** * @Inject * @var Response */ protected $response;
- 在任意类中extends AbstractController
class IndexController extends AbstractController { public function index() { $data = [ 'order_id' => 1234 ]; return $this->response->success($data); } }
- 效果
{
"code": 0,
"data": {
"order_id": 1234
}
}