member-doc/response.md
zhouyangyang a4b70328c6 提交
2022-06-14 19:36:15 +08:00

890 B
Raw Blame History

统一响应

目前会员中心工程中app/Controller/Response/AppResponse.php 实现控制器controller统一响应开发者可以controller 实例化AppResponse进行响应切记勿用注解或di注入AppResponse导致AppResponse单列以至于返回数据异常。

代码示例:



    /**
     * @param  ApiLayerService  $service
     * @return ResponseInterface
     * @throws MemberException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function get(ApiLayerService $service): ResponseInterface
    {
        $result = $service->inject($this->request)
            ->handle([
                'logic_config' => [
                    EnumConstService::class,
                    'getEnum'
                ]
            ]);
        return (new AppResponse())->setResult($result)->success();
    }