latvijas-talrunis / api-auth-client-maker
针对特定目的的API客户端生成器
dev-main
2023-02-10 12:10 UTC
Requires
- symfony/http-client: ^6.2
This package is not auto-updated.
Last update: 2024-09-21 17:44:31 UTC
README
来自 LT/Utils
如何在symfony中设置
- 使用以下方式安装
composer require latvijas-talrunis/api-auth-client-maker
如果您的项目无法找到ClientMaker,这可能有助于
composer dump-autoload
- 更新您项目的
services:
LT\Utils\ApiClientMaker\ClientMaker:
arguments:
$authServiceUrl: '%env(string:AUTH_SERVICE_URL)%'
$authServiceUser: '%env(string:AUTH_SERVICE_USER)%'
$authServicePassword: '%env(string:AUTH_SERVICE_PASSWORD)%'
- 更新您的.env文件,包含以下3个变量
AUTH_SERVICE_URL=http://url.to.the.auth.service
AUTH_SERVICE_USER=root
AUTH_SERVICE_PASSWORD=
- 并且对于控制器
它需要一个类属性来保存实例化的ClientMaker
public $clientMaker;
需要在客户端构造函数中设置
public function __construct(ApiClientMaker $serviceMediatorClientMaker){
$this->clientMaker = $serviceMediatorClientMaker;
}
然后它将在该特定控制器的每个方法中可用
#[Route('/test')]
public function index(): Response
{
// authorized symfony http client
$client = $this->clientMaker->getClient();
}