heartide/response

基于Hyperf2.0扩展Response

1.0.2 2020-07-15 09:54 UTC

This package is auto-updated.

Last update: 2024-09-24 11:33:32 UTC


README

  • 基于Hyperf2.0中的Response扩展

运行环境

请确保操作环境满足以下要求

  • PHP >= 7.2
  • Swoole PHP扩展 >= 4.4,且禁用Short Name
  • OpenSSL PHP扩展
  • JSON PHP扩展
  • PDO PHP扩展(如果您需要使用MySQL客户端)
  • Redis PHP扩展(如果您需要使用Redis客户端)
  • Protobuf PHP扩展(如果您需要使用gRPC服务器或客户端)

安装

  • 引入组件
$ 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
  }
}