|
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 <https://opensource.org/licenses/MIT>. |
|
9
|
|
|
// |
|
10
|
|
|
// --------------------------------------------------------------------- |
|
11
|
|
|
|
|
12
|
|
|
namespace Linode\VPC\Repository; |
|
13
|
|
|
|
|
14
|
|
|
use Linode\Entity; |
|
15
|
|
|
use Linode\Internal\AbstractRepository; |
|
16
|
|
|
use Linode\LinodeClient; |
|
17
|
|
|
use Linode\VPC\VPCSubnet; |
|
18
|
|
|
use Linode\VPC\VPCSubnetRepositoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
|
22
|
|
|
*/ |
|
23
|
|
|
class VPCSubnetRepository extends AbstractRepository implements VPCSubnetRepositoryInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @param int $vpcId The `id` of the VPC. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(LinodeClient $client, protected int $vpcId) |
|
29
|
|
|
{ |
|
30
|
|
|
parent::__construct($client); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function createVPCSubnet(array $parameters = []): VPCSubnet |
|
34
|
|
|
{ |
|
35
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
|
36
|
|
|
$contents = $response->getBody()->getContents(); |
|
37
|
|
|
$json = json_decode($contents, true); |
|
38
|
|
|
|
|
39
|
|
|
return new VPCSubnet($this->client, $json); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function updateVPCSubnet(int $vpcSubnetId, array $parameters = []): VPCSubnet |
|
43
|
|
|
{ |
|
44
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $vpcSubnetId), $parameters); |
|
45
|
|
|
$contents = $response->getBody()->getContents(); |
|
46
|
|
|
$json = json_decode($contents, true); |
|
47
|
|
|
|
|
48
|
|
|
return new VPCSubnet($this->client, $json); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function deleteVPCSubnet(int $vpcSubnetId): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $vpcSubnetId)); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
protected function getBaseUri(): string |
|
57
|
|
|
{ |
|
58
|
|
|
return sprintf('/vpcs/%s/subnets', $this->vpcId); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function getSupportedFields(): array |
|
62
|
|
|
{ |
|
63
|
|
|
return [ |
|
64
|
|
|
VPCSubnet::FIELD_ID, |
|
65
|
|
|
VPCSubnet::FIELD_LABEL, |
|
66
|
|
|
VPCSubnet::FIELD_IPV4, |
|
67
|
|
|
VPCSubnet::FIELD_LINODES, |
|
68
|
|
|
VPCSubnet::FIELD_CREATED, |
|
69
|
|
|
VPCSubnet::FIELD_UPDATED, |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function jsonToEntity(array $json): Entity |
|
74
|
|
|
{ |
|
75
|
|
|
return new VPCSubnet($this->client, $json); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|