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\Domains; |
13
|
|
|
|
14
|
|
|
use Linode\Entity\Domains\Domain; |
15
|
|
|
use Linode\Entity\Entity; |
16
|
|
|
use Linode\Internal\AbstractRepository; |
17
|
|
|
use Linode\Repository\Domains\DomainRepositoryInterface; |
18
|
|
|
|
19
|
|
|
class DomainRepository extends AbstractRepository implements DomainRepositoryInterface |
20
|
|
|
{ |
21
|
1 |
|
public function create(array $parameters): Domain |
22
|
|
|
{ |
23
|
1 |
|
$this->checkParametersSupport($parameters); |
24
|
|
|
|
25
|
1 |
|
$response = $this->client->api($this->client::REQUEST_POST, $this->getBaseUri(), $parameters); |
26
|
1 |
|
$contents = $response->getBody()->getContents(); |
27
|
1 |
|
$json = json_decode($contents, true); |
28
|
|
|
|
29
|
1 |
|
return new Domain($this->client, $json); |
30
|
|
|
} |
31
|
|
|
|
32
|
1 |
|
public function update(int $id, array $parameters): Domain |
33
|
|
|
{ |
34
|
1 |
|
$this->checkParametersSupport($parameters); |
35
|
|
|
|
36
|
1 |
|
$response = $this->client->api($this->client::REQUEST_PUT, sprintf('%s/%s', $this->getBaseUri(), $id), $parameters); |
37
|
1 |
|
$contents = $response->getBody()->getContents(); |
38
|
1 |
|
$json = json_decode($contents, true); |
39
|
|
|
|
40
|
1 |
|
return new Domain($this->client, $json); |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
public function delete(int $id): void |
44
|
|
|
{ |
45
|
1 |
|
$this->client->api($this->client::REQUEST_DELETE, sprintf('%s/%s', $this->getBaseUri(), $id)); |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
public function import(string $domain, string $remote_nameserver): Domain |
49
|
|
|
{ |
50
|
1 |
|
$parameters = [ |
51
|
1 |
|
'domain' => $domain, |
52
|
1 |
|
'remote_nameserver' => $remote_nameserver, |
53
|
1 |
|
]; |
54
|
|
|
|
55
|
1 |
|
$response = $this->client->api($this->client::REQUEST_POST, sprintf('%s/import', $this->getBaseUri()), $parameters); |
56
|
1 |
|
$contents = $response->getBody()->getContents(); |
57
|
1 |
|
$json = json_decode($contents, true); |
58
|
|
|
|
59
|
1 |
|
return new Domain($this->client, $json); |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
public function clone(int $id, string $domain): Domain |
63
|
|
|
{ |
64
|
1 |
|
$parameters = [ |
65
|
1 |
|
'domain' => $domain, |
66
|
1 |
|
]; |
67
|
|
|
|
68
|
1 |
|
$response = $this->client->api($this->client::REQUEST_POST, sprintf('%s/clone', $this->getBaseUri()), $parameters); |
69
|
1 |
|
$contents = $response->getBody()->getContents(); |
70
|
1 |
|
$json = json_decode($contents, true); |
71
|
|
|
|
72
|
1 |
|
return new Domain($this->client, $json); |
73
|
|
|
} |
74
|
|
|
|
75
|
6 |
|
protected function getBaseUri(): string |
76
|
|
|
{ |
77
|
6 |
|
return '/domains'; |
78
|
|
|
} |
79
|
|
|
|
80
|
3 |
|
protected function getSupportedFields(): array |
81
|
|
|
{ |
82
|
3 |
|
return [ |
83
|
3 |
|
Domain::FIELD_ID, |
84
|
3 |
|
Domain::FIELD_DOMAIN, |
85
|
3 |
|
Domain::FIELD_TYPE, |
86
|
3 |
|
Domain::FIELD_STATUS, |
87
|
3 |
|
Domain::FIELD_SOA_EMAIL, |
88
|
3 |
|
Domain::FIELD_GROUP, |
89
|
3 |
|
Domain::FIELD_DESCRIPTION, |
90
|
3 |
|
Domain::FIELD_TTL_SEC, |
91
|
3 |
|
Domain::FIELD_REFRESH_SEC, |
92
|
3 |
|
Domain::FIELD_RETRY_SEC, |
93
|
3 |
|
Domain::FIELD_EXPIRE_SEC, |
94
|
3 |
|
Domain::FIELD_MASTER_IPS, |
95
|
3 |
|
Domain::FIELD_AXFR_IPS, |
96
|
3 |
|
]; |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
protected function jsonToEntity(array $json): Entity |
100
|
|
|
{ |
101
|
1 |
|
return new Domain($this->client, $json); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|