Repository navigation
Expand file tree
/
Copy pathKVFactory.php
More file actions
53 lines (44 loc) · 1.41 KB
/
Copy pathKVFactory.php
File metadata and controls
53 lines (44 loc) · 1.41 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
42
43
44
45
46
47
48
49
50
51
52
53
<?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\Etcd;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Etcd\Exception\ClientNotFindException;
use Hyperf\Guzzle\HandlerStackFactory;
use Psr\Container\ContainerInterface;
use function Hyperf\Support\make;
class KVFactory
{
public function __invoke(ContainerInterface $container)
{
$config = $container->get(ConfigInterface::class);
$uri = $config->get('etcd.uri', 'http://127.0.0.1:2379');
$version = $config->get('etcd.version', 'v3beta');
$options = $config->get('etcd.options', []);
$factory = $container->get(HandlerStackFactory::class);
return $this->make($uri, $version, $options, $factory);
}
protected function make(string $uri, string $version, array $options, HandlerStackFactory $factory)
{
$params = [
'uri' => $uri,
'version' => $version,
'options' => $options,
'factory' => $factory,
];
switch ($version) {
case 'v3':
case 'v3alpha':
case 'v3beta':
return make(V3\KV::class, $params);
}
throw new ClientNotFindException("KV of {$version} is not find.");
}
}