-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClient.php
159 lines (151 loc) · 4.45 KB
/
Client.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* @since Jul 2022
* @author Haydar KULEKCI <[email protected]>
*/
namespace Skytable;
use RuntimeException;
use Skytable\Exception\ActionException;
/**
* @Client is the client class of Skytable.
*
* @link \Skytable\Action\Dbsize
* @method dbsize(): TypeInterface
*
* @link \Skytable\Action\Del
* @method del(string $key): TypeInterface
*
* @link \Skytable\Action\Exists
* @method exists(array $keys): TypeInterface
*
* @link \Skytable\Action\Flushdb
* @method flushdb(): TypeInterface
*
* @link \Skytable\Action\Get
* @method get(string $key): TypeInterface
*
* @link \Skytable\Action\Heya
* @method heya(): TypeInterface
*
* @link \Skytable\Action\Lget
* @method lget(string $key): TypeInterface
*
* @link \Skytable\Action\Lget\First
* @method lget_first(string $key): TypeInterface
*
* @link \Skytable\Action\Lget\Last
* @method lget_last(string $key): TypeInterface
*
* @link \Skytable\Action\Lget\Len
* @method lget_len(string $key): TypeInterface
*
* @link \Skytable\Action\Lget\Limit
* @method lget_limit(string $key, int $limit = null): TypeInterface
*
* @link \Skytable\Action\Lget\Range
* @method lget_range(string $key, int $start, int $stop = null): TypeInterface
*
* @link \Skytable\Action\Lget\Valueat
* @method lget_valueat(string $key, int $index): TypeInterface
*
* @link \Skytable\Action\Lset
* @method lset(string $key, array $values): TypeInterface
*
* @link \Skytable\Action\Mget
* @method mget(array $keys): TypeInterface
*
* @link \Skytable\Action\Mpop
* @method mpop(array $keys): TypeInterface
*
* @link \Skytable\Action\Pop
* @method pop(string $key): TypeInterface
*
* @link \Skytable\Action\Select
* @method select(string $name): TypeInterface
*
* @link \Skytable\Action\Set
* @method set(string $key, $value): TypeInterface
*
* @link \Skytable\Action\Update
* @method update(string $key, $value): TypeInterface
*
* @link \Skytable\Action\Whereami
* @method whereami(): TypeInterface
*
* @link \Skytable\Action\Auth\Claim
* @method auth_claim(string $originKey): TypeInterface
*
* @link \Skytable\Action\Auth\Claim
* @method auth_login(string $username, string $token): TypeInterface
*
* @link \Skytable\Action\Create\Keyspace
* @method create_keyspace(string $name): TypeInterface
*
* @link \Skytable\Action\Create\Table
* @method create_table(string $name, string $keymap): TypeInterface
*
* @link \Skytable\Action\Drop\Keyspace
* @method drop_keyspace(string $name): TypeInterface
*
* @link \Skytable\Action\Lmod\Pop
* @method lmod_pop(string $key): TypeInterface
*
* @link \Skytable\Action\Lmod\Clear
* @method lmod_clear(string $key): TypeInterface
*
* @link \Skytable\Action\Lmod\Push
* @method lmod_push(string $key, string $value): TypeInterface
*
* @link \Skytable\Action\Lmod\Rpop
* @method lmod_rpop(string $key): TypeInterface
*
* @link \Skytable\Action\Sys\Info\Protocol
* @method sys_info_protocol(): TypeInterface
*
* @link \Skytable\Action\Sys\Info\Protover
* @method sys_info_protover(): TypeInterface
*
* @link \Skytable\Action\Sys\Info\Version
* @method sys_info_version(): TypeInterface
*
* @link \Skytable\Action\Sys\Metric\Health
* @method sys_metric_health(): TypeInterface
*
* @link \Skytable\Action\Sys\Metric\Storage
* @method sys_metric_storage(): TypeInterface
*
* @link \Skytable\Action\Inspect\Keyspaces
* @method inspect_keyspaces(): TypeInterface
*
* @link \Skytable\Action\Inspect\Keyspace
* @method inspect_keyspace(string $entity = null): TypeInterface
*
* @link \Skytable\Action\Inspect\Table
* @method inspect_table(string $entity = null): TypeInterface
*/
class Client
{
private Connection $connection;
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
public function execute(ActionsBuilder $payload): Response
{
return $this->connection->execute($payload);
}
/**
* @throws ActionException
*/
public function __call($name, $arguments)
{
$actionBuilder = new ActionsBuilder();
$className = str_replace(' ', '\\', ucwords(str_replace('_', ' ', $name)));
$classNameWithNamespace = __NAMESPACE__ . '\\Action\\' . $className;
if (!class_exists($classNameWithNamespace)) {
throw new ActionException("Action $className not found");
}
$actionBuilder->add(new $classNameWithNamespace(...$arguments));
return $this->connection->execute($actionBuilder)->getLastData();
}
}