1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AcquiaCloudApi\Endpoints; |
4
|
|
|
|
5
|
|
|
use AcquiaCloudApi\Connector\ClientInterface; |
6
|
|
|
use AcquiaCloudApi\Response\BranchesResponse; |
7
|
|
|
use AcquiaCloudApi\Response\OperationResponse; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Client |
11
|
|
|
* @package AcquiaCloudApi\CloudApi |
12
|
|
|
*/ |
13
|
|
|
class Code 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 code branches and tags in an application. |
31
|
|
|
* |
32
|
|
|
* @param string $applicationUuid |
33
|
|
|
* @return BranchesResponse |
34
|
|
|
*/ |
35
|
|
|
public function getAll($applicationUuid) |
36
|
|
|
{ |
37
|
|
|
return new BranchesResponse( |
38
|
|
|
$this->client->request( |
|
|
|
|
39
|
|
|
'get', |
40
|
|
|
"/applications/${applicationUuid}/code" |
41
|
|
|
) |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Deploys a code branch/tag to an environment. |
47
|
|
|
* |
48
|
|
|
* @param string $environmentUuid |
49
|
|
|
* @param string $branch |
50
|
|
|
* @return OperationResponse |
51
|
|
|
*/ |
52
|
|
|
public function switch($environmentUuid, $branch) |
53
|
|
|
{ |
54
|
|
|
|
55
|
|
|
$options = [ |
56
|
|
|
'form_params' => [ |
57
|
|
|
'branch' => $branch, |
58
|
|
|
], |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
return new OperationResponse( |
62
|
|
|
$this->client->request( |
|
|
|
|
63
|
|
|
'post', |
64
|
|
|
"/environments/${environmentUuid}/code/actions/switch", |
65
|
|
|
$options |
66
|
|
|
) |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Deploys code from one environment to another environment. |
72
|
|
|
* |
73
|
|
|
* @param string $environmentFromUuid |
74
|
|
|
* @param string $environmentToUuid |
75
|
|
|
* @param string $commitMessage |
76
|
|
|
*/ |
77
|
|
|
public function deploy($environmentFromUuid, $environmentToUuid, $commitMessage = null) |
78
|
|
|
{ |
79
|
|
|
|
80
|
|
|
$options = [ |
81
|
|
|
'form_params' => [ |
82
|
|
|
'source' => $environmentFromUuid, |
83
|
|
|
'message' => $commitMessage, |
84
|
|
|
], |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
return new OperationResponse( |
88
|
|
|
$this->client->request( |
|
|
|
|
89
|
|
|
'post', |
90
|
|
|
"/environments/${environmentToUuid}/code", |
91
|
|
|
$options |
92
|
|
|
) |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|