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\MetadataEndpoint; |
17
|
|
|
use Cwd\PowerDNSClient\Endpoints\ServersEndpoint; |
18
|
|
|
use Cwd\PowerDNSClient\Endpoints\ZonesEndpoint; |
19
|
|
|
use Cwd\PowerDNSClient\Model\Zone; |
20
|
|
|
|
21
|
|
|
class PowerDNSClient |
22
|
|
|
{ |
23
|
|
|
/** @var Client */ |
24
|
|
|
private $client; |
25
|
|
|
|
26
|
|
|
/** @var ServersEndpoint */ |
27
|
|
|
private $serversEndpoint; |
28
|
|
|
|
29
|
|
|
/** @var ZonesEndpoint */ |
30
|
|
|
private $zonesEndpoint; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
private $defaultServerId = 'localhost'; |
34
|
|
|
|
35
|
|
|
public function __construct(Client $client) |
36
|
|
|
{ |
37
|
|
|
$this->client = $client; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function metadata($zone): MetadataEndpoint |
41
|
|
|
{ |
42
|
|
|
$zoneId = $zone; |
43
|
|
|
|
44
|
|
|
if ($zone instanceof Zone) { |
45
|
|
|
$zoneId = $zone->getId(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return new MetadataEndpoint($this->getClient(), $this->getDefaultServerId(), $zoneId); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function servers(): ServersEndpoint |
52
|
|
|
{ |
53
|
|
|
if (null === $this->serversEndpoint) { |
54
|
|
|
$this->serversEndpoint = new ServersEndpoint($this->getClient(), $this->getDefaultServerId()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this->serversEndpoint; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function zones(): ZonesEndpoint |
61
|
|
|
{ |
62
|
|
|
if (null === $this->zonesEndpoint) { |
63
|
|
|
$this->zonesEndpoint = new ZonesEndpoint($this->getClient(), $this->getDefaultServerId()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $this->zonesEndpoint; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return Client |
71
|
|
|
*/ |
72
|
|
|
public function getClient(): Client |
73
|
|
|
{ |
74
|
|
|
return $this->client; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function getDefaultServerId(): string |
81
|
|
|
{ |
82
|
|
|
return $this->defaultServerId; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $defaultServerId |
87
|
|
|
*/ |
88
|
|
|
public function setDefaultServerId(string $defaultServerId): void |
89
|
|
|
{ |
90
|
|
|
$this->defaultServerId = $defaultServerId; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|