54 lines
1.3 KiB
Markdown
54 lines
1.3 KiB
Markdown
|
## 创建
|
|||
|
|
|||
|
示例:
|
|||
|
```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直接调用相关依赖。
|