-
Notifications
You must be signed in to change notification settings - Fork 59
/
KV.php
46 lines (36 loc) · 1.19 KB
/
KV.php
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
<?php
namespace Consul\Services;
use Consul\Client;
use Consul\ClientInterface;
use Consul\ConsulResponse;
use Consul\OptionsResolver;
final class KV
{
private ClientInterface $client;
public function __construct(?ClientInterface $client = null)
{
$this->client = $client ?: new Client();
}
public function get(string $key, array $options = []): ConsulResponse
{
$params = [
'query' => OptionsResolver::resolve($options, ['dc', 'recurse', 'keys', 'separator', 'raw', 'stale', 'consistent', 'default']),
];
return $this->client->get('v1/kv/'.$key, $params);
}
public function put(string $key, $value, array $options = []): ConsulResponse
{
$params = [
'body' => $value,
'query' => OptionsResolver::resolve($options, ['dc', 'flags', 'cas', 'acquire', 'release']),
];
return $this->client->put('v1/kv/'.$key, $params);
}
public function delete(string $key, array $options = []): ConsulResponse
{
$params = [
'query' => OptionsResolver::resolve($options, ['dc', 'recurse']),
];
return $this->client->delete('v1/kv/'.$key, $params);
}
}