1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the DigitalOceanV2 library. |
5
|
|
|
* |
6
|
|
|
* (c) Antoine Corcy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DigitalOceanV2\Entity; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Yassir Hannoun <[email protected]> |
16
|
|
|
* @author Graham Campbell <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
final class Droplet extends AbstractEntity |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
public $id; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $name; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
public $memory; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var int |
37
|
|
|
*/ |
38
|
|
|
public $vcpus; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var int |
42
|
|
|
*/ |
43
|
|
|
public $disk; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var Region |
47
|
|
|
*/ |
48
|
|
|
public $region; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var Image |
52
|
|
|
*/ |
53
|
|
|
public $image; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var Kernel |
57
|
|
|
*/ |
58
|
|
|
public $kernel; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var Size |
62
|
|
|
*/ |
63
|
|
|
public $size; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
public $sizeSlug; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var bool |
72
|
|
|
*/ |
73
|
|
|
public $locked; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
public $createdAt; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var string |
82
|
|
|
*/ |
83
|
|
|
public $status; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var Tags[] |
87
|
|
|
*/ |
88
|
|
|
public $tags = []; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var Network[] |
92
|
|
|
*/ |
93
|
|
|
public $networks = []; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var int[] |
97
|
|
|
*/ |
98
|
|
|
public $backupIds = []; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var string[] |
102
|
|
|
*/ |
103
|
|
|
public $volumeIds = []; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var int[] |
107
|
|
|
*/ |
108
|
|
|
public $snapshotIds = []; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @var string[] |
112
|
|
|
*/ |
113
|
|
|
public $features = []; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @var bool |
117
|
|
|
*/ |
118
|
|
|
public $backupsEnabled; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var bool |
122
|
|
|
*/ |
123
|
|
|
public $privateNetworkingEnabled; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @var bool |
127
|
|
|
*/ |
128
|
|
|
public $ipv6Enabled; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @var bool |
132
|
|
|
*/ |
133
|
|
|
public $virtIOEnabled; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @var NextBackupWindow |
137
|
|
|
*/ |
138
|
|
|
public $nextBackupWindow; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param array $parameters |
142
|
|
|
*/ |
143
|
|
|
public function build(array $parameters) |
144
|
|
|
{ |
145
|
|
|
foreach ($parameters as $property => $value) { |
146
|
|
|
switch ($property) { |
147
|
|
|
case 'networks': |
148
|
|
|
if (is_object($value)) { |
149
|
|
|
if (property_exists($value, 'v4')) { |
150
|
|
|
foreach ($value->v4 as $subProperty => $subValue) { |
151
|
|
|
$subValue->version = 4; |
152
|
|
|
$this->networks[] = new Network($subValue); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
if (property_exists($value, 'v6')) { |
157
|
|
|
foreach ($value->v6 as $subProperty => $subValue) { |
158
|
|
|
$subValue->version = 6; |
159
|
|
|
$subValue->cidr = $subValue->netmask; |
160
|
|
|
$subValue->netmask = null; |
161
|
|
|
$this->networks[] = new Network($subValue); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
unset($parameters[$property]); |
166
|
|
|
break; |
167
|
|
|
|
168
|
|
|
case 'kernel': |
169
|
|
|
if (is_object($value)) { |
170
|
|
|
$this->kernel = new Kernel($value); |
171
|
|
|
} |
172
|
|
|
unset($parameters[$property]); |
173
|
|
|
break; |
174
|
|
|
|
175
|
|
|
case 'size': |
176
|
|
|
if (is_object($value)) { |
177
|
|
|
$this->size = new Size($value); |
178
|
|
|
} |
179
|
|
|
unset($parameters[$property]); |
180
|
|
|
break; |
181
|
|
|
|
182
|
|
|
case 'region': |
183
|
|
|
if (is_object($value)) { |
184
|
|
|
$this->region = new Region($value); |
185
|
|
|
} |
186
|
|
|
unset($parameters[$property]); |
187
|
|
|
break; |
188
|
|
|
|
189
|
|
|
case 'image': |
190
|
|
|
if (is_object($value)) { |
191
|
|
|
$this->image = new Image($value); |
192
|
|
|
} |
193
|
|
|
unset($parameters[$property]); |
194
|
|
|
break; |
195
|
|
|
|
196
|
|
|
case 'next_backup_window': |
197
|
|
|
$this->nextBackupWindow = new NextBackupWindow($value); |
198
|
|
|
unset($parameters[$property]); |
199
|
|
|
break; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
parent::build($parameters); |
204
|
|
|
|
205
|
|
|
if (is_array($this->features) && count($this->features)) { |
206
|
|
|
$this->backupsEnabled = in_array('backups', $this->features); |
207
|
|
|
$this->virtIOEnabled = in_array('virtio', $this->features); |
208
|
|
|
$this->privateNetworkingEnabled = in_array('private_networking', $this->features); |
209
|
|
|
$this->ipv6Enabled = in_array('ipv6', $this->features); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @param string $createdAt |
215
|
|
|
*/ |
216
|
|
|
public function setCreatedAt($createdAt) |
217
|
|
|
{ |
218
|
|
|
$this->createdAt = static::convertDateTime($createdAt); |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|