1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AcquiaCloudApi\Endpoints; |
4
|
|
|
|
5
|
|
|
use AcquiaCloudApi\Connector\ClientInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class CloudApiBase |
9
|
|
|
* |
10
|
|
|
* @package AcquiaCloudApi\CloudApi |
11
|
|
|
*/ |
12
|
|
|
abstract class CloudApiBase implements CloudApiInterface |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var ClientInterface The API client. |
17
|
|
|
*/ |
18
|
|
|
protected $client; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Client constructor. |
22
|
|
|
* |
23
|
|
|
* @param ClientInterface $client |
24
|
|
|
*/ |
25
|
|
|
public function __construct(ClientInterface $client) |
26
|
|
|
{ |
27
|
|
|
$this->client = $client; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $link |
32
|
|
|
* @return mixed |
33
|
|
|
*/ |
34
|
|
|
public function getLinkedResource($link) |
35
|
|
|
{ |
36
|
|
|
// Parse only the path part of the URL. |
37
|
|
|
$path = parse_url($link, PHP_URL_PATH); |
38
|
|
|
|
39
|
|
|
// Remove /api from the path as this is already added by the Connector. |
40
|
|
|
$path = substr($path, 4); |
41
|
|
|
|
42
|
|
|
// Convert the path into an array so we can work out how to handle the response. |
43
|
|
|
$segments = explode('/', rtrim($path)); |
44
|
|
|
|
45
|
|
|
// Get the final array element which we use to determine the response type. |
46
|
|
|
$type = end($segments); |
47
|
|
|
|
48
|
|
|
switch($type) { |
49
|
|
|
case 'alerts': |
50
|
|
|
return new \AcquiaCloudApi\Response\InsightAlertsResponse( |
51
|
|
|
$this->client->request('get', $path) |
|
|
|
|
52
|
|
|
); |
53
|
|
|
break; |
|
|
|
|
54
|
|
|
case 'applications': |
55
|
|
|
return new \AcquiaCloudApi\Response\ApplicationsResponse( |
56
|
|
|
$this->client->request('get', $path) |
|
|
|
|
57
|
|
|
); |
58
|
|
|
break; |
59
|
|
|
case 'backups': |
60
|
|
|
return new \AcquiaCloudApi\Response\BackupsResponse( |
61
|
|
|
$this->client->request('get', $path) |
|
|
|
|
62
|
|
|
); |
63
|
|
|
break; |
64
|
|
|
case 'code': |
65
|
|
|
return new \AcquiaCloudApi\Response\BranchesResponse( |
66
|
|
|
$this->client->request('get', $path) |
|
|
|
|
67
|
|
|
); |
68
|
|
|
break; |
69
|
|
|
case 'crons': |
70
|
|
|
return new \AcquiaCloudApi\Response\CronsResponse( |
71
|
|
|
$this->client->request('get', $path) |
|
|
|
|
72
|
|
|
); |
73
|
|
|
break; |
74
|
|
|
case 'databases': |
75
|
|
|
return new \AcquiaCloudApi\Response\DatabasesResponse( |
76
|
|
|
$this->client->request('get', $path) |
|
|
|
|
77
|
|
|
); |
78
|
|
|
break; |
79
|
|
|
case 'domains': |
80
|
|
|
return new \AcquiaCloudApi\Response\DomainsResponse( |
81
|
|
|
$this->client->request('get', $path) |
|
|
|
|
82
|
|
|
); |
83
|
|
|
break; |
84
|
|
|
case 'download': |
85
|
|
|
break; |
86
|
|
|
case 'environments': |
87
|
|
|
return new \AcquiaCloudApi\Response\EnvironmentsResponse( |
88
|
|
|
$this->client->request('get', $path) |
|
|
|
|
89
|
|
|
); |
90
|
|
|
break; |
91
|
|
|
case 'events': |
92
|
|
|
break; |
93
|
|
|
case 'features': |
94
|
|
|
break; |
95
|
|
|
case 'ides': |
96
|
|
|
return new \AcquiaCloudApi\Response\IdesResponse( |
97
|
|
|
$this->client->request('get', $path) |
|
|
|
|
98
|
|
|
); |
99
|
|
|
break; |
100
|
|
|
case 'insight': |
101
|
|
|
return new \AcquiaCloudApi\Response\InsightsResponse( |
102
|
|
|
$this->client->request('get', $path) |
|
|
|
|
103
|
|
|
); |
104
|
|
|
break; |
105
|
|
|
case 'logs': |
106
|
|
|
return new \AcquiaCloudApi\Response\LogsResponse( |
107
|
|
|
$this->client->request('get', $path) |
|
|
|
|
108
|
|
|
); |
109
|
|
|
break; |
110
|
|
|
case 'members': |
111
|
|
|
return new \AcquiaCloudApi\Response\MembersResponse( |
112
|
|
|
$this->client->request('get', $path) |
|
|
|
|
113
|
|
|
); |
114
|
|
|
break; |
115
|
|
|
case 'metrics': |
116
|
|
|
return new \AcquiaCloudApi\Response\MetricsResponse( |
117
|
|
|
$this->client->request('get', $path) |
|
|
|
|
118
|
|
|
); |
119
|
|
|
break; |
120
|
|
|
case 'modules': |
121
|
|
|
return new \AcquiaCloudApi\Response\InsightModulesResponse( |
122
|
|
|
$this->client->request('get', $path) |
|
|
|
|
123
|
|
|
); |
124
|
|
|
break; |
125
|
|
|
case 'permissions': |
126
|
|
|
return new \AcquiaCloudApi\Response\PermissionsResponse( |
127
|
|
|
$this->client->request('get', $path) |
|
|
|
|
128
|
|
|
); |
129
|
|
|
break; |
130
|
|
|
case 'servers':return new \AcquiaCloudApi\Response\ServersResponse( |
131
|
|
|
$this->client->request('get', $path) |
|
|
|
|
132
|
|
|
); |
133
|
|
|
break; |
134
|
|
|
case 'settings': |
135
|
|
|
break; |
136
|
|
|
case 'ssl': |
137
|
|
|
return new \AcquiaCloudApi\Response\SslCertificatesResponse( |
138
|
|
|
$this->client->request('get', $path) |
|
|
|
|
139
|
|
|
); |
140
|
|
|
break; |
141
|
|
|
case 'tasks': |
142
|
|
|
break; |
143
|
|
|
case 'teams': |
144
|
|
|
return new \AcquiaCloudApi\Response\TeamsResponse( |
145
|
|
|
$this->client->request('get', $path) |
|
|
|
|
146
|
|
|
); |
147
|
|
|
break; |
148
|
|
|
case 'variables': |
149
|
|
|
return new \AcquiaCloudApi\Response\VariablesResponse( |
150
|
|
|
$this->client->request('get', $path) |
|
|
|
|
151
|
|
|
); |
152
|
|
|
break; |
153
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
var_dump(get_defined_vars()); |
|
|
|
|
157
|
|
|
throw new \Exception('Not found'); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|