1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Afonso\Dns; |
6
|
|
|
|
7
|
|
|
class Response |
8
|
|
|
{ |
9
|
|
|
const RCODE_NO_ERROR = 0x00; |
10
|
|
|
const RCODE_FORMAT_ERROR = 0x01; |
11
|
|
|
const RCODE_SERVER_FAILURE = 0x02; |
12
|
|
|
const RCODE_NAME_ERROR = 0x03; |
13
|
|
|
const RCODE_NOT_IMPLEMENTED = 0x04; |
14
|
|
|
const RCODE_REFUSED = 0x05; |
15
|
|
|
|
16
|
|
|
protected $isAuthoritative; |
17
|
|
|
|
18
|
|
|
protected $isRecursionAvailable; |
19
|
|
|
|
20
|
|
|
protected $type; |
21
|
|
|
|
22
|
|
|
protected $records = []; |
23
|
|
|
|
24
|
24 |
|
public function isAuthoritative(): bool |
25
|
|
|
{ |
26
|
24 |
|
return $this->isAuthoritative; |
27
|
|
|
} |
28
|
|
|
|
29
|
24 |
|
public function setAuthoritative(bool $isAuthoritative): void |
30
|
|
|
{ |
31
|
24 |
|
$this->isAuthoritative = $isAuthoritative; |
32
|
24 |
|
} |
33
|
|
|
|
34
|
24 |
|
public function isRecursionAvailable(): bool |
35
|
|
|
{ |
36
|
24 |
|
return $this->isRecursionAvailable; |
37
|
|
|
} |
38
|
|
|
|
39
|
24 |
|
public function setRecursionAvailable(bool $isRecursionAvailable): void |
40
|
|
|
{ |
41
|
24 |
|
$this->isRecursionAvailable = $isRecursionAvailable; |
42
|
24 |
|
} |
43
|
|
|
|
44
|
42 |
|
public function getType(): int |
45
|
|
|
{ |
46
|
42 |
|
return $this->type; |
47
|
|
|
} |
48
|
|
|
|
49
|
45 |
|
public function setType(int $type): void |
50
|
|
|
{ |
51
|
45 |
|
if (!$this->isValidResponseType($type)) { |
52
|
3 |
|
throw new \InvalidArgumentException("'${type}' is not a valid DNS response type"); |
53
|
|
|
} |
54
|
42 |
|
$this->type = $type; |
55
|
42 |
|
} |
56
|
|
|
|
57
|
27 |
|
public function getResourceRecords(): array |
58
|
|
|
{ |
59
|
27 |
|
return $this->records; |
60
|
|
|
} |
61
|
|
|
|
62
|
24 |
|
public function addResourceRecord(ResourceRecordInterface $record): void |
63
|
|
|
{ |
64
|
24 |
|
$this->records[] = $record; |
65
|
24 |
|
} |
66
|
|
|
|
67
|
45 |
|
private function isValidResponseType(int $type): bool |
68
|
|
|
{ |
69
|
|
|
$validTypes = [ |
70
|
45 |
|
self::RCODE_NO_ERROR, |
71
|
45 |
|
self::RCODE_FORMAT_ERROR, |
72
|
45 |
|
self::RCODE_SERVER_FAILURE, |
73
|
45 |
|
self::RCODE_NAME_ERROR, |
74
|
45 |
|
self::RCODE_NOT_IMPLEMENTED, |
75
|
45 |
|
self::RCODE_REFUSED |
76
|
|
|
]; |
77
|
45 |
|
return in_array($type, $validTypes); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|