27 lines
890 B
Markdown
27 lines
890 B
Markdown
|
## 统一响应
|
|||
|
目前会员中心工程中app/Controller/Response/AppResponse.php 实现控制器(controller)统一响应,开发者可以controller 实例化AppResponse进行响应,切记勿用注解或di注入AppResponse,导致AppResponse单列以至于返回数据异常。
|
|||
|
|
|||
|
代码示例:
|
|||
|
```php
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @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();
|
|||
|
}
|
|||
|
|
|||
|
```
|