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

54 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 创建
示例:
```php
class CompanyController
{
/**
* @Inject
* @var CompanyRequest
*/
protected CompanyRequest $companyRequest;
/**
* @param ApiLayerService $service
* @return ResponseInterface
* @throws MemberException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function companiesForSimple(ApiLayerService $service): ResponseInterface
{
$result = $service->inject($this->companyRequest)->handle([
'logic_config' => [
CompanyService::class,//调用服务类
'getCompanySimpleList'//对应方法
]
]);
return (new AppResponse())->setResult($result)->success();
}
```
### 说明
1. 所有控制器方法 必须依赖ApiLayerService
2. ApiLayerService->inject 注入当前请求对象
3. 由handle注入服务调用编排配置
开发者初期只需要记住这样固定编排格式即可,配置如下
```php
[
'logic_config' => [
CompanyService::class,//调用服务类
'getCompanySimpleList'//对应方法
]
]
```
直白了说等同于 (new CompanyService(ApiConfigService $config))->getCompanySimpleList(); 并且将一系列依赖直接注入该对象中开发者在CompanyService直接调用相关依赖。