1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AcquiaCloudApi\Endpoints; |
4
|
|
|
|
5
|
|
|
use AcquiaCloudApi\Connector\ClientInterface; |
6
|
|
|
use AcquiaCloudApi\Response\DatabasesResponse; |
7
|
|
|
use AcquiaCloudApi\Response\OperationResponse; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Client |
11
|
|
|
* @package AcquiaCloudApi\CloudApi |
12
|
|
|
*/ |
13
|
|
|
class Databases implements CloudApi |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** @var ClientInterface The API client. */ |
17
|
|
|
protected $client; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Client constructor. |
21
|
|
|
* |
22
|
|
|
* @param ClientInterface $client |
23
|
|
|
*/ |
24
|
|
|
public function __construct(ClientInterface $client) |
25
|
|
|
{ |
26
|
|
|
$this->client = $client; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Shows all databases in an application. |
31
|
|
|
* |
32
|
|
|
* @param string $applicationUuid |
33
|
|
|
* @return DatabasesResponse |
34
|
|
|
*/ |
35
|
|
|
public function getAll($applicationUuid) |
36
|
|
|
{ |
37
|
|
|
return new DatabasesResponse( |
38
|
|
|
$this->client->request( |
|
|
|
|
39
|
|
|
'get', |
40
|
|
|
"/applications/${applicationUuid}/databases" |
41
|
|
|
) |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Create a new database. |
47
|
|
|
* |
48
|
|
|
* @param string $applicationUuid |
49
|
|
|
* @param string $name |
50
|
|
|
* @return OperationResponse |
51
|
|
|
*/ |
52
|
|
|
public function create($applicationUuid, $name) |
53
|
|
|
{ |
54
|
|
|
$options = [ |
55
|
|
|
'form_params' => [ |
56
|
|
|
'name' => $name, |
57
|
|
|
], |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
return new OperationResponse( |
61
|
|
|
$this->client->request('post', "/applications/${applicationUuid}/databases", $options) |
|
|
|
|
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Delete a database. |
67
|
|
|
* |
68
|
|
|
* @param string $applicationUuid |
69
|
|
|
* @param string $name |
70
|
|
|
* @return OperationResponse |
71
|
|
|
*/ |
72
|
|
|
public function delete($applicationUuid, $name) |
73
|
|
|
{ |
74
|
|
|
return new OperationResponse( |
75
|
|
|
$this->client->request('delete', "/applications/${applicationUuid}/databases/${name}") |
|
|
|
|
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Copies a database from an environment to an environment. |
81
|
|
|
* |
82
|
|
|
* @param string $environmentFromUuid |
83
|
|
|
* @param string $dbName |
84
|
|
|
* @param string $environmentToUuid |
85
|
|
|
* @return OperationResponse |
86
|
|
|
*/ |
87
|
|
|
public function copy($environmentFromUuid, $dbName, $environmentToUuid) |
88
|
|
|
{ |
89
|
|
|
$options = [ |
90
|
|
|
'form_params' => [ |
91
|
|
|
'name' => $dbName, |
92
|
|
|
'source' => $environmentFromUuid, |
93
|
|
|
], |
94
|
|
|
]; |
95
|
|
|
|
96
|
|
|
return new OperationResponse( |
97
|
|
|
$this->client->request('post', "/environments/${environmentToUuid}/databases", $options) |
|
|
|
|
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|