|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AcquiaCloudApi\Endpoints; |
|
4
|
|
|
|
|
5
|
|
|
use AcquiaCloudApi\Connector\ConnectorInterface; |
|
6
|
|
|
use AcquiaCloudApi\Connector\ClientInterface; |
|
7
|
|
|
use AcquiaCloudApi\Exception\LinkedResourceNotImplementedException; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class CloudApiBase |
|
11
|
|
|
* |
|
12
|
|
|
* @package AcquiaCloudApi\CloudApi |
|
13
|
|
|
*/ |
|
14
|
|
|
abstract class CloudApiBase implements CloudApiInterface |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var ClientInterface The API client. |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $client; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Client constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param ClientInterface $client |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(ClientInterface $client) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->client = $client; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param array{type:string, path:string, responseClass:class-string} $link |
|
|
|
|
|
|
34
|
|
|
* @return mixed |
|
35
|
|
|
* @throws LinkedResourceNotImplementedException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getLinkedResource($link) |
|
38
|
|
|
{ |
|
39
|
|
|
// Remove the base URI from the path as this is already added by the Connector when we call request(). |
|
40
|
|
|
$path = str_replace(ConnectorInterface::BASE_URI, '', $link['path']); |
|
41
|
|
|
$type = $link['type']; |
|
42
|
|
|
$responseClass = $link['responseClass']; |
|
43
|
|
|
|
|
44
|
|
|
$classMap = [ |
|
45
|
|
|
'alerts' => '\AcquiaCloudApi\Response\InsightAlertsResponse', |
|
46
|
|
|
'applications' => '\AcquiaCloudApi\Response\ApplicationsResponse', |
|
47
|
|
|
'backups' => '\AcquiaCloudApi\Response\BackupsResponse', |
|
48
|
|
|
'code' => '\AcquiaCloudApi\Response\BranchesResponse', |
|
49
|
|
|
'crons' => '\AcquiaCloudApi\Response\CronsResponse', |
|
50
|
|
|
'databases' => '\AcquiaCloudApi\Response\DatabasesResponse', |
|
51
|
|
|
'domains' => '\AcquiaCloudApi\Response\DomainsResponse', |
|
52
|
|
|
'environments' => '\AcquiaCloudApi\Response\EnvironmentsResponse', |
|
53
|
|
|
'ides' => '\AcquiaCloudApi\Response\IdesResponse', |
|
54
|
|
|
'insight' => '\AcquiaCloudApi\Response\InsightsResponse', |
|
55
|
|
|
'logs' => '\AcquiaCloudApi\Response\LogsResponse', |
|
56
|
|
|
'members' => '\AcquiaCloudApi\Response\MembersResponse', |
|
57
|
|
|
'metrics' => '\AcquiaCloudApi\Response\MetricsResponse', |
|
58
|
|
|
'modules' => '\AcquiaCloudApi\Response\InsightModulesResponse', |
|
59
|
|
|
'notification' => '\AcquiaCloudApi\Response\NotificationResponse', |
|
60
|
|
|
'permissions' => '\AcquiaCloudApi\Response\PermissionsResponse', |
|
61
|
|
|
'self' => $responseClass, |
|
62
|
|
|
'servers' => '\AcquiaCloudApi\Response\ServersResponse', |
|
63
|
|
|
'ssl' => '\AcquiaCloudApi\Response\SslCertificatesResponse', |
|
64
|
|
|
'teams' => '\AcquiaCloudApi\Response\TeamsResponse', |
|
65
|
|
|
'variables' => '\AcquiaCloudApi\Response\VariablesResponse', |
|
66
|
|
|
]; |
|
67
|
|
|
|
|
68
|
|
|
if (isset($classMap[$type])) { |
|
69
|
|
|
return new $classMap[$type]( |
|
70
|
|
|
$this->client->request('get', $path) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
throw new LinkedResourceNotImplementedException($type . ' link not implemented in this SDK. Please file an issue here: https://github.com/typhonius/acquia-php-sdk-v2/issues'); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|