heartide/response

基于Hyperf2.0扩展Response

1.0.2 2020-07-15 09:54 UTC

This package is auto-updated.

Last update: 2024-03-24 10:28:25 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
  }
}