|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// --------------------------------------------------------------------- |
|
4
|
|
|
// |
|
5
|
|
|
// Copyright (C) 2018-2024 Artem Rodygin |
|
6
|
|
|
// |
|
7
|
|
|
// You should have received a copy of the MIT License along with |
|
8
|
|
|
// this file. If not, see <http://opensource.org/licenses/MIT>. |
|
9
|
|
|
// |
|
10
|
|
|
// --------------------------------------------------------------------- |
|
11
|
|
|
|
|
12
|
|
|
namespace Linode\Internal\Linode; |
|
13
|
|
|
|
|
14
|
|
|
use Linode\Entity\Linode; |
|
15
|
|
|
use Linode\Entity\Networking\IPAddress; |
|
16
|
|
|
use Linode\LinodeClient; |
|
17
|
|
|
use Linode\Repository\Linode\LinodeNetworkRepositoryInterface; |
|
18
|
|
|
|
|
19
|
|
|
class LinodeNetworkRepository implements LinodeNetworkRepositoryInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param int $linodeId ID of the Linode to look up |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(protected LinodeClient $client, protected int $linodeId) {} |
|
25
|
|
|
|
|
26
|
1 |
|
public function getNetworkInformation(): Linode\NetworkInformation |
|
27
|
|
|
{ |
|
28
|
1 |
|
$response = $this->client->api($this->client::REQUEST_GET, $this->getBaseUri()); |
|
29
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
30
|
1 |
|
$json = json_decode($contents, true); |
|
31
|
|
|
|
|
32
|
1 |
|
return new Linode\NetworkInformation($this->client, $json); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
public function find(string $id): IPAddress |
|
36
|
|
|
{ |
|
37
|
1 |
|
$response = $this->client->api($this->client::REQUEST_GET, sprintf('%s/%s', $this->getBaseUri(), $id)); |
|
38
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
39
|
1 |
|
$json = json_decode($contents, true); |
|
40
|
|
|
|
|
41
|
1 |
|
return new IPAddress($this->client, $json); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
public function allocate(bool $public, string $type = IPAddress::TYPE_IP4): IPAddress |
|
45
|
|
|
{ |
|
46
|
1 |
|
$parameters = [ |
|
47
|
1 |
|
'public' => $public, |
|
48
|
1 |
|
'type' => $type, |
|
49
|
1 |
|
]; |
|
50
|
|
|
|
|
51
|
1 |
|
$response = $this->client->api($this->client::REQUEST_POST, $this->getBaseUri(), $parameters); |
|
52
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
53
|
1 |
|
$json = json_decode($contents, true); |
|
54
|
|
|
|
|
55
|
1 |
|
return new IPAddress($this->client, $json); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
public function update(string $id, array $parameters): IPAddress |
|
59
|
|
|
{ |
|
60
|
1 |
|
$response = $this->client->api($this->client::REQUEST_PUT, sprintf('%s/%s', $this->getBaseUri(), $id), $parameters); |
|
61
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
62
|
1 |
|
$json = json_decode($contents, true); |
|
63
|
|
|
|
|
64
|
1 |
|
return new IPAddress($this->client, $json); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
public function delete(string $id): void |
|
68
|
|
|
{ |
|
69
|
1 |
|
$this->client->api($this->client::REQUEST_DELETE, sprintf('%s/%s', $this->getBaseUri(), $id)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Returns base URI to the repository-specific API. |
|
74
|
|
|
*/ |
|
75
|
6 |
|
protected function getBaseUri(): string |
|
76
|
|
|
{ |
|
77
|
6 |
|
return sprintf('/linode/instances/%s/ips', $this->linodeId); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|