1 | <?php |
||
9 | abstract class Provider |
||
10 | { |
||
11 | /** |
||
12 | * @var \Laravel\Forge\ApiProvider |
||
13 | */ |
||
14 | protected $api; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $payload = []; |
||
20 | |||
21 | /** |
||
22 | * Create new server provider instance. |
||
23 | * |
||
24 | * @param \Laravel\Forge\ApiProvider $api |
||
25 | */ |
||
26 | public function __construct(ApiProvider $api) |
||
31 | |||
32 | /** |
||
33 | * Initializes server provider. |
||
34 | */ |
||
35 | protected function initProvider() |
||
39 | |||
40 | /** |
||
41 | * Server provider name. |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | public function provider() |
||
49 | |||
50 | /** |
||
51 | * Server provider regions list. |
||
52 | * |
||
53 | * @return array |
||
54 | */ |
||
55 | public function regions() |
||
59 | |||
60 | /** |
||
61 | * Server provider server sizes. |
||
62 | * |
||
63 | * @return array |
||
64 | */ |
||
65 | public function sizes() |
||
69 | |||
70 | /** |
||
71 | * Available PHP versions. |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | public function phpVersions() |
||
79 | |||
80 | /** |
||
81 | * Validates payload before sending to Forge API. |
||
82 | * |
||
83 | * @return bool|array |
||
84 | */ |
||
85 | public function validate() |
||
89 | |||
90 | /** |
||
91 | * Determines if given region is available at current provider. |
||
92 | * |
||
93 | * @param string $region |
||
94 | * |
||
95 | * @return bool |
||
96 | */ |
||
97 | public function regionAvailable(string $region) |
||
101 | |||
102 | /** |
||
103 | * Determines if given memory size is available at current provider. |
||
104 | * |
||
105 | * @param string|int $memory |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | public function memoryAvailable($memory) |
||
113 | |||
114 | /** |
||
115 | * Determines if given resource exists in resources list. |
||
116 | * |
||
117 | * @param array $resources |
||
118 | * @param mixed $resource |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | protected function resourceAvailable(array $resources, $resource) |
||
126 | |||
127 | /** |
||
128 | * Determines if given key exists in current payload. |
||
129 | * |
||
130 | * @param string $key |
||
131 | * |
||
132 | * @return bool |
||
133 | */ |
||
134 | public function hasPayload(string $key): bool |
||
138 | |||
139 | /** |
||
140 | * Set credential ID to create server with. |
||
141 | * |
||
142 | * @param int $credentialId |
||
143 | * |
||
144 | * @return static |
||
145 | */ |
||
146 | public function usingCredential(int $credentialId) |
||
152 | |||
153 | /** |
||
154 | * Set new server name. |
||
155 | * |
||
156 | * @param string $name |
||
157 | * |
||
158 | * @return static |
||
159 | */ |
||
160 | public function identifiedAs(string $name) |
||
166 | |||
167 | /** |
||
168 | * Set memory / server size. |
||
169 | * |
||
170 | * @param int|string $memory |
||
171 | * |
||
172 | * @return static |
||
173 | */ |
||
174 | public function withMemoryOf($memory) |
||
184 | |||
185 | /** |
||
186 | * Set server region. |
||
187 | * |
||
188 | * @param string $region |
||
189 | * |
||
190 | * @return static |
||
191 | */ |
||
192 | public function at(string $region) |
||
202 | |||
203 | /** |
||
204 | * Set PHP version. |
||
205 | * |
||
206 | * @param int|string $version |
||
207 | * |
||
208 | * @return static |
||
209 | */ |
||
210 | public function runningPhp($version) |
||
222 | |||
223 | /** |
||
224 | * Indicates that server should be provisioned with MariaDB instead of MySQL. |
||
225 | * |
||
226 | * @param string $database = 'forge' |
||
227 | * |
||
228 | * @return static |
||
229 | */ |
||
230 | public function withMariaDb(string $database = 'forge') |
||
237 | |||
238 | /** |
||
239 | * Indicates that server should be provisioned with MySQL. |
||
240 | * |
||
241 | * @param string $database = 'forge' |
||
242 | * |
||
243 | * @return static |
||
244 | */ |
||
245 | public function withMysql(string $database = 'forge') |
||
252 | |||
253 | /** |
||
254 | * Indicates that server should be provisioned as load balancer. |
||
255 | * |
||
256 | * @param bool $install = true |
||
257 | * |
||
258 | * @deprecated since 1.3.1 |
||
259 | * @see Provider::asNodeBalancer() |
||
260 | * |
||
261 | * @return static |
||
262 | */ |
||
263 | public function asLoadBalancer(bool $install = true) |
||
267 | |||
268 | /** |
||
269 | * Indicates that server should be provisioned as load balancer. |
||
270 | * |
||
271 | * @param bool $install = true |
||
272 | * |
||
273 | * @return static |
||
274 | */ |
||
275 | public function asNodeBalancer(bool $install = true) |
||
279 | |||
280 | /** |
||
281 | * Servers ID that the new server should be connected to. |
||
282 | * |
||
283 | * @param array $servers |
||
284 | * |
||
285 | * @return static |
||
286 | */ |
||
287 | public function connectedTo(array $servers) |
||
293 | |||
294 | /** |
||
295 | * Public IP address. |
||
296 | * |
||
297 | * @param string $ip |
||
298 | * |
||
299 | * @return static |
||
300 | */ |
||
301 | public function usingPublicIp(string $ip) |
||
307 | |||
308 | /** |
||
309 | * Private IP address. |
||
310 | * |
||
311 | * @param string $ip |
||
312 | * |
||
313 | * @return static |
||
314 | */ |
||
315 | public function usingPrivateIp(string $ip) |
||
321 | |||
322 | /** |
||
323 | * Create new server. |
||
324 | * |
||
325 | * @throws \GuzzleHttp\Exception\RequestException |
||
326 | * @throws \InvalidArgumentException |
||
327 | * |
||
328 | * @return \Laravel\Forge\Server |
||
329 | */ |
||
330 | public function save() |
||
346 | |||
347 | /** |
||
348 | * Sort payload data by key name. |
||
349 | * |
||
350 | * @return array |
||
351 | */ |
||
352 | protected function sortPayload(): array |
||
360 | |||
361 | /** |
||
362 | * Toggle boolean payload key. |
||
363 | * |
||
364 | * @param string $key |
||
365 | * @param bool $install |
||
366 | * |
||
367 | * @return static |
||
368 | */ |
||
369 | protected function togglePayload(string $key, bool $install) |
||
379 | } |
||
380 |