1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the CwdPowerDNS Client |
5
|
|
|
* |
6
|
|
|
* (c) 2018 cwd.at GmbH <[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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Cwd\PowerDNSClient; |
15
|
|
|
|
16
|
|
|
use Cwd\PowerDNSClient\Endpoints\CryptokeysEndpoint; |
17
|
|
|
use Cwd\PowerDNSClient\Endpoints\MetadataEndpoint; |
18
|
|
|
use Cwd\PowerDNSClient\Endpoints\ServersEndpoint; |
19
|
|
|
use Cwd\PowerDNSClient\Endpoints\ZonesEndpoint; |
20
|
|
|
use Cwd\PowerDNSClient\Model\Zone; |
21
|
|
|
|
22
|
|
|
class PowerDNSClient |
23
|
|
|
{ |
24
|
|
|
/** @var Client */ |
25
|
|
|
private $client; |
26
|
|
|
|
27
|
|
|
/** @var ServersEndpoint */ |
28
|
|
|
private $serversEndpoint; |
29
|
|
|
|
30
|
|
|
/** @var ZonesEndpoint */ |
31
|
|
|
private $zonesEndpoint; |
32
|
|
|
|
33
|
|
|
/** @var CryptokeysEndpoint */ |
34
|
|
|
private $cryptokeysEndpoint; |
|
|
|
|
35
|
|
|
|
36
|
|
|
/** @var string */ |
37
|
|
|
private $defaultServerId = 'localhost'; |
38
|
|
|
|
39
|
|
|
public function __construct(Client $client) |
40
|
|
|
{ |
41
|
|
|
$this->client = $client; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function metadata($zone): MetadataEndpoint |
45
|
|
|
{ |
46
|
|
|
$zoneId = $zone; |
47
|
|
|
|
48
|
|
|
if ($zone instanceof Zone) { |
49
|
|
|
$zoneId = $zone->getId(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return new MetadataEndpoint($this->getClient(), $this->getDefaultServerId(), $zoneId); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function servers(): ServersEndpoint |
56
|
|
|
{ |
57
|
|
|
if (null === $this->serversEndpoint) { |
58
|
|
|
$this->serversEndpoint = new ServersEndpoint($this->getClient(), $this->getDefaultServerId()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $this->serversEndpoint; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function zones(): ZonesEndpoint |
65
|
|
|
{ |
66
|
|
|
if (null === $this->zonesEndpoint) { |
67
|
|
|
$this->zonesEndpoint = new ZonesEndpoint($this->getClient(), $this->getDefaultServerId()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $this->zonesEndpoint; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function cryptokeys($zone): CryptokeysEndpoint |
74
|
|
|
{ |
75
|
|
|
$zoneId = $zone; |
76
|
|
|
|
77
|
|
|
if ($zone instanceof Zone) { |
78
|
|
|
$zoneId = $zone->getId(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return new CryptokeysEndpoint($this->getClient(), $this->getDefaultServerId(), $zoneId); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return Client |
86
|
|
|
*/ |
87
|
|
|
public function getClient(): Client |
88
|
|
|
{ |
89
|
|
|
return $this->client; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getDefaultServerId(): string |
96
|
|
|
{ |
97
|
|
|
return $this->defaultServerId; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $defaultServerId |
102
|
|
|
*/ |
103
|
|
|
public function setDefaultServerId(string $defaultServerId): void |
104
|
|
|
{ |
105
|
|
|
$this->defaultServerId = $defaultServerId; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|