|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of Badcow DNS Library. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Samuel Williams <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Badcow\DNS\Rdata; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Used to create RData of types that have not yet been implemented in the library. |
|
18
|
|
|
*/ |
|
19
|
|
|
class PolymorphicRdata implements RdataInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* The RData type. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string|null |
|
25
|
|
|
*/ |
|
26
|
|
|
private $type; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string|null |
|
30
|
|
|
*/ |
|
31
|
|
|
private $data; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var int|null |
|
35
|
|
|
*/ |
|
36
|
|
|
private $typeCode; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* PolymorphicRdata constructor. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string|null $type |
|
42
|
|
|
* @param string|null $data |
|
43
|
|
|
*/ |
|
44
|
1 |
|
public function __construct(?string $type = null, ?string $data = null) |
|
45
|
|
|
{ |
|
46
|
1 |
|
if (null !== $type) { |
|
47
|
1 |
|
$this->setType($type); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
if (null !== $data) { |
|
51
|
1 |
|
$this->setData($data); |
|
52
|
|
|
} |
|
53
|
1 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $type |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function setType(string $type): void |
|
59
|
|
|
{ |
|
60
|
|
|
try { |
|
61
|
1 |
|
$this->typeCode = TypeCodes::getTypeCode($type); |
|
62
|
1 |
|
} catch (\Exception $e) { |
|
63
|
1 |
|
$this->typeCode = 65535; |
|
64
|
|
|
} |
|
65
|
1 |
|
$this->type = $type; |
|
66
|
1 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function getType(): string |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->type ?? ''; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getTypeCode(): int |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->getTypeCode(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @deprecated |
|
86
|
|
|
* |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
public function output(): string |
|
90
|
|
|
{ |
|
91
|
|
|
@trigger_error('Method RdataInterface::output() has been deprecated. Use RdataInterface::toText().', E_USER_DEPRECATED); |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
return $this->toText(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param string $data |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function setData(string $data): void |
|
100
|
|
|
{ |
|
101
|
1 |
|
$this->data = $data; |
|
102
|
1 |
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return string|null |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function getData(): ?string |
|
108
|
|
|
{ |
|
109
|
1 |
|
return $this->data; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* {@inheritdoc} |
|
114
|
|
|
*/ |
|
115
|
1 |
|
public function toText(): string |
|
116
|
|
|
{ |
|
117
|
1 |
|
return $this->getData() ?? ''; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* {@inheritdoc} |
|
122
|
|
|
*/ |
|
123
|
|
|
public function toWire(): string |
|
124
|
|
|
{ |
|
125
|
|
|
// TODO: Implement toWire() method. |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* {@inheritdoc} |
|
130
|
|
|
*/ |
|
131
|
|
|
public static function fromText(string $text): RdataInterface |
|
132
|
|
|
{ |
|
133
|
|
|
// TODO: Implement fromText() method. |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* {@inheritdoc} |
|
138
|
|
|
*/ |
|
139
|
|
|
public static function fromWire(string $rdata): RdataInterface |
|
140
|
|
|
{ |
|
141
|
|
|
// TODO: Implement fromWire() method. |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: