Repository navigation
Expand file tree
/
Copy pathClientFactory.php
More file actions
41 lines (36 loc) · 1.54 KB
/
Copy pathClientFactory.php
File metadata and controls
41 lines (36 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\ConfigApollo;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Guzzle\ClientFactory as GuzzleClientFactory;
use Hyperf\Support\Network;
use Psr\Container\ContainerInterface;
use function Hyperf\Support\make;
class ClientFactory
{
public function __invoke(ContainerInterface $container)
{
$config = $container->get(ConfigInterface::class);
/** @var Option $option */
$option = make(Option::class);
$option->setServer($config->get('config_center.drivers.apollo.server', 'http://127.0.0.1:8080'))
->setAppid($config->get('config_center.drivers.apollo.appid', ''))
->setCluster($config->get('config_center.drivers.apollo.cluster', ''))
->setClientIp($config->get('config_center.drivers.apollo.client_ip', Network::ip()))
->setPullTimeout($config->get('config_center.drivers.apollo.pull_timeout', 10))
->setIntervalTimeout($config->get('config_center.drivers.apollo.interval_timeout', 60))
->setSecret($config->get('config_center.drivers.apollo.secret', ''));
$httpClientFactory = function (array $options = []) use ($container) {
return $container->get(GuzzleClientFactory::class)->create($options);
};
return make(Client::class, compact('option', 'httpClientFactory'));
}
}