1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ArangoClient; |
6
|
|
|
|
7
|
|
|
use GuzzleHttp\Exception\GuzzleException; |
8
|
|
|
|
9
|
|
|
class DatabaseClient |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var Connector |
13
|
|
|
*/ |
14
|
|
|
protected Connector $connector; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Documents constructor. |
18
|
|
|
* @param Connector $connector |
19
|
|
|
*/ |
20
|
|
|
public function __construct(Connector $connector) |
21
|
|
|
{ |
22
|
|
|
$this->connector = $connector; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return array<mixed> |
27
|
|
|
* @throws GuzzleException|Exceptions\ArangoDbException |
28
|
|
|
*/ |
29
|
|
|
public function read(): array |
30
|
|
|
{ |
31
|
|
|
return (array) $this->connector->request('get', '/_api/database/current'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return array<mixed> |
36
|
|
|
* |
37
|
|
|
* @throws GuzzleException|Exceptions\ArangoDbException |
38
|
|
|
*/ |
39
|
|
|
public function listDatabases(): array |
40
|
|
|
{ |
41
|
|
|
return (array) $this->connector->request('get', '/_api/database'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return array<mixed> |
46
|
|
|
* |
47
|
|
|
* @throws GuzzleException|Exceptions\ArangoDbException |
48
|
|
|
*/ |
49
|
|
|
public function listMyDatabases(): array |
50
|
|
|
{ |
51
|
|
|
return (array) $this->connector->request('get', '/_api/database/user'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $name |
56
|
|
|
* @param null $options |
|
|
|
|
57
|
|
|
* @param null $users |
|
|
|
|
58
|
|
|
* @return bool |
59
|
|
|
* @throws Exceptions\ArangoDbException |
60
|
|
|
* @throws GuzzleException |
61
|
|
|
*/ |
62
|
|
|
public function create(string $name, $options = null, $users = null): bool |
63
|
|
|
{ |
64
|
|
|
$database = json_encode((object)['name' => $name, 'options' => $options, 'users' => $users]); |
65
|
|
|
|
66
|
|
|
return (bool) $this->connector->request('post', '/_api/database', ['body' => $database]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $name |
71
|
|
|
* @return bool |
72
|
|
|
* @throws Exceptions\ArangoDbException |
73
|
|
|
* @throws GuzzleException |
74
|
|
|
*/ |
75
|
|
|
public function delete(string $name): bool |
76
|
|
|
{ |
77
|
|
|
$uri = '/_api/database/' . $name; |
78
|
|
|
|
79
|
|
|
return (bool) $this->connector->request('delete', $uri); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|