Skip to content

Commit c05d027

Browse files
committed
mass update changes
1 parent d44e380 commit c05d027

24 files changed

+298
-67
lines changed

phpunit.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
stopOnRisky="true"
1313
failOnRisky="true"
1414
failOnEmptyTestSuite="true"
15+
displayDetailsOnTestsThatTriggerWarnings="true"
1516
displayDetailsOnIncompleteTests="true"
1617
>
1718
<testsuites>
@@ -26,7 +27,8 @@
2627
</testsuite>
2728
</testsuites>
2829
<php>
30+
<ini name="display_errors" value="On" />
31+
<ini name="display_startup_errors" value="On" />
2932
<env name="APP_ENV" value="testing"/>
30-
<env name="DEFAULT_TIMEOUT" value="3.5"/>
3133
</php>
3234
</phpunit>

src/Abstracts/AbstractResourceRecordType.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ protected function parseMessage(): void
125125
'Response header length is invalid'
126126
);
127127
}
128-
129128
[
130129
'type' => $type,
131130
'class' => $class,
@@ -201,11 +200,11 @@ public function getHeader(): string
201200
}
202201

203202
/**
204-
* @return string
203+
* @inheritdoc
205204
*/
206-
public function getMessage(): string
205+
public function getMessage(): PacketMessageInterface
207206
{
208-
return $this->getHeader() . $this->getRData();
207+
return $this->message;
209208
}
210209

211210
/**
@@ -315,7 +314,7 @@ public function toArray(): array
315314
'host' => $this->getName(),
316315
'class' => $this->getClass()->getName(),
317316
'ttl' => $this->getTTL(),
318-
'type' => $this->getType(),
317+
'type' => $this->getType()->getName(),
319318
'value' => $this->getValue(),
320319
];
321320
}

src/Interfaces/Packet/PacketHeaderInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ public function withARCount(int $ar) : static;
304304
*/
305305
public function withANCount(int $an) : static;
306306

307+
/**
308+
* With NS count
309+
*
310+
* @param int $ns
311+
* @return $this
312+
*/
313+
public function withNSCount(int $ns) : static;
314+
307315
/**
308316
* With QD Count
309317
* @param int $qd

src/Interfaces/Packet/PacketResourceRecordsInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public function getRecords(): array;
4646
*/
4747
public function getFilteredType(string $type, bool $single = false) : null|array|ResourceRecordTypeInterface;
4848

49+
/**
50+
* Return array records
51+
* @uses ResourceRecordTypeInterface::toArray()
52+
* @return array<array>
53+
*/
54+
public function toArray() : array;
55+
4956
/**
5057
* @return Traversable<ResourceRecordTypeInterface>
5158
*/

src/Interfaces/ResourceRecord/ResourceRecordTypeInterface.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ public function getOffsetPosition() : int;
7474
public function getHeader() : string;
7575

7676
/**
77-
* Get message raw response answer data
77+
* Get message raw all response answer data
7878
*
79-
* @return string
79+
* @return PacketMessageInterface
8080
*/
81-
public function getMessage(): string;
81+
public function getMessage(): PacketMessageInterface;
8282

8383
/**
8484
* The dns name
@@ -141,7 +141,8 @@ public function getQueryMessage() : string;
141141
/**
142142
* Return array data
143143
*
144-
* @return array
144+
* @return array like dns_get_record()
145+
* @see \dns_get_record()
145146
*/
146147
public function toArray() : array;
147148
}

src/Packet/Header.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,17 @@ public function withANCount(int $an): static
340340
return $obj;
341341
}
342342

343+
/**
344+
* @inheritdoc
345+
*/
346+
public function withNSCount(int $ns): static
347+
{
348+
$obj = clone $this;
349+
$obj->nscount = $ns;
350+
$obj->message = null;
351+
return $obj;
352+
}
353+
343354
/**
344355
* @inheritdoc
345356
*/

src/Packet/Question.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public function __serialize(): array
194194
* @param int $type
195195
* @param int $class
196196
* @return Question
197+
* @noinspection PhpDocMissingThrowsInspection
197198
*/
198199
public static function fromFilteredResponse(
199200
string $name,

src/Packet/Records.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use ArrayAccess\DnsRecord\Interfaces\ResourceRecord\ResourceRecordTypeInterface;
88
use ArrayIterator;
99
use Traversable;
10+
use function array_map;
11+
use function array_values;
1012
use function md5;
1113
use function serialize;
1214
use function strtoupper;
@@ -86,6 +88,14 @@ public function getFilteredType(string $type, bool $single = false) : null|array
8688
return $result === [] ? null : $result;
8789
}
8890

91+
/**
92+
* @inheritdoc
93+
*/
94+
public function toArray(): array
95+
{
96+
return array_map(static fn ($e) => $e->toArray(), array_values($this->getRecords()));
97+
}
98+
8999
/**
90100
* @inheritdoc
91101
*/

src/Resolver.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ public function createQueryOpcode(
152152
$class = trim($class?:IN::NAME)?:IN::NAME;
153153
$class = Lookup::resourceClass($class);
154154
$type = Lookup::resourceType($type);
155-
$isOpt = $type->getName() === OPT::TYPE;
155+
$typeName = $type->getName();
156+
$isOpt = $typeName === OPT::TYPE;
156157
if ($isOpt) { // if is OPT fallback to A
157158
$type = 'A';
158159
}
@@ -165,12 +166,13 @@ public function createQueryOpcode(
165166
}
166167
$dns = new DnsServerStorage(...$ss);
167168
}
169+
170+
$header = Header::createQueryHeader($opcode, null, $adFlag, $cdFlag, $recurse);
168171
$requestData = new RequestData(
169-
Header::createQueryHeader($opcode, null, $adFlag, $cdFlag, $recurse),
172+
$header,
170173
$dns,
171174
$question
172175
);
173-
174176
if ($isOpt || $dnsSec) {
175177
$requestData
176178
->getAdditionalRecords()

src/ResourceRecord/RRTypes/CERT.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use ArrayAccess\DnsRecord\Abstracts\AbstractResourceRecordType;
77
use function array_values;
8+
use function base64_encode;
89
use function substr;
910

1011
/**
@@ -56,26 +57,27 @@ protected function parseRData(string $message, int $rdataOffset): void
5657
//
5758
// copy the certificate
5859
//
59-
$this->certificate = substr($this->rData, 5, $this->rdLength - 5);
60+
$this->certificate = base64_encode(substr($this->rData, 5, $this->rdLength - 5));
6061
}
6162

62-
public function getFormat(): ?int
63+
public function getFormat(): int
6364
{
64-
return $this->format??null;
65+
return $this->format;
6566
}
6667

67-
public function getKeyTag(): ?int
68+
public function getKeyTag(): int
6869
{
69-
return $this->keyTag??null;
70+
return $this->keyTag;
7071
}
7172

72-
public function getAlgorithm(): ?string
73+
public function getAlgorithm(): string
7374
{
74-
return $this->algorithm??null;
75+
return $this->algorithm;
7576
}
7677

77-
public function getCertificate(): ?string
78+
public function getCertificate(): string
7879
{
79-
return $this->certificate??null;
80+
return $this->certificate;
8081
}
8182
}
83+
// @todo add toArray()

src/ResourceRecord/RRTypes/CNAME.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,25 @@ class CNAME extends AbstractResourceRecordType
2020
{
2121
const TYPE = 'CNAME';
2222

23-
protected string $cname;
24-
2523
/**
2624
* @inheritdoc
2725
*/
2826
protected function parseRData(string $message, int $rdataOffset): void
2927
{
30-
$this->cname = Buffer::readLabel($message, $rdataOffset);
28+
$this->value = Buffer::readLabel($message, $rdataOffset);
3129
}
3230

33-
public function getCname(): string
31+
/**
32+
* @inheritdoc
33+
*/
34+
public function toArray(): array
3435
{
35-
return $this->cname;
36+
return [
37+
'host' => $this->getName(),
38+
'class' => $this->getClass()->getName(),
39+
'ttl' => $this->getTTL(),
40+
'type' => $this->getType()->getName(),
41+
'target' => $this->getValue(),
42+
];
3643
}
3744
}

src/ResourceRecord/RRTypes/DNSKEY.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ protected function parseRData(string $message, int $rdataOffset): void
113113
$this->zoneSep = ((int)$flags[15]) === 1;
114114
}
115115
}
116+
// @todo add toArray()

src/ResourceRecord/RRTypes/HINFO.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,29 @@ protected function parseRData(string $message, int $rdataOffset): void
4040
$this->rdLength - strlen($this->cpu)
4141
);
4242
}
43+
44+
public function getCpu(): string
45+
{
46+
return $this->cpu;
47+
}
48+
49+
public function getOs(): string
50+
{
51+
return $this->os;
52+
}
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
public function toArray(): array
58+
{
59+
return [
60+
'host' => $this->getName(),
61+
'class' => $this->getClass()->getName(),
62+
'ttl' => $this->getTTL(),
63+
'type' => $this->getType()->getName(),
64+
'cpu' => $this->getCpu(),
65+
'os' => $this->getOs(),
66+
];
67+
}
4368
}

src/ResourceRecord/RRTypes/IXFR.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ArrayAccess\DnsRecord\ResourceRecord\RRTypes;
5+
6+
use ArrayAccess\DnsRecord\Abstracts\AbstractResourceRecordType;
7+
use ArrayAccess\DnsRecord\Interfaces\ResourceRecord\ResourceRecordMetaTypeInterface;
8+
9+
/**
10+
* A IXFR Query format - RFC1995 Section &
11+
*
12+
* +---------------------------------------------------+
13+
* Header | OPCODE=SQUERY |
14+
* +---------------------------------------------------+
15+
* Question | QNAME=JAIN.AD.JP., QCLASS=IN, QTYPE=IXFR |
16+
* +---------------------------------------------------+
17+
* Answer | <empty> |
18+
* +---------------------------------------------------+
19+
* Authority | JAIN.AD.JP. IN SOA serial=1 |
20+
* +---------------------------------------------------+
21+
* Additional | <empty> |
22+
* +---------------------------------------------------+
23+
*
24+
* IXFR Response Format
25+
*
26+
* +---------------------------------------------------+
27+
* Header | OPCODE=SQUERY, RESPONSE |
28+
* +---------------------------------------------------+
29+
* Question | QNAME=JAIN.AD.JP., QCLASS=IN, QTYPE=IXFR |
30+
* +---------------------------------------------------+
31+
* Answer | JAIN.AD.JP. IN SOA serial=3 |
32+
* | JAIN.AD.JP. IN NS NS.JAIN.AD.JP. |
33+
* | NS.JAIN.AD.JP. IN A 133.69.136.1 |
34+
* | JAIN-BB.JAIN.AD.JP. IN A 133.69.136.3 |
35+
* | JAIN-BB.JAIN.AD.JP. IN A 192.41.197.2 |
36+
* | JAIN.AD.JP. IN SOA serial=3 |
37+
* +---------------------------------------------------+
38+
* Authority | <empty> |
39+
* +---------------------------------------------------+
40+
* Additional | <empty> |
41+
* +---------------------------------------------------+
42+
*
43+
* @link https://datatracker.ietf.org/doc/html/rfc1995#section-7
44+
*/
45+
class IXFR extends AbstractResourceRecordType implements ResourceRecordMetaTypeInterface
46+
{
47+
const TYPE = 'IXFR';
48+
}
49+
// @todo add completion()

src/ResourceRecord/RRTypes/MG.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ protected function parseRData(string $message, int $rdataOffset): void
3131
$this->value = Buffer::readLabel($message, $rdataOffset);
3232
}
3333
}
34+
// @todo add toArray()

src/ResourceRecord/RRTypes/MR.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ protected function parseRData(string $message, int $rdataOffset): void
3131
$this->value = Buffer::readLabel($message, $rdataOffset);
3232
}
3333
}
34+
// @todo add toArray()

src/ResourceRecord/RRTypes/MX.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,19 @@ public function getExchange(): string
5555
{
5656
return $this->exchange;
5757
}
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
public function toArray(): array
63+
{
64+
return [
65+
'host' => $this->getName(),
66+
'class' => $this->getClass()->getName(),
67+
'ttl' => $this->getTTL(),
68+
'type' => $this->getType()->getName(),
69+
'pri' => $this->getPreference(),
70+
'target' => $this->getExchange(),
71+
];
72+
}
5873
}

src/ResourceRecord/RRTypes/NS.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,18 @@ protected function parseRData(string $message, int $rdataOffset): void
3030
{
3131
$this->value = Buffer::readLabel($message, $rdataOffset);
3232
}
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
public function toArray(): array
38+
{
39+
return [
40+
'host' => $this->getName(),
41+
'class' => $this->getClass()->getName(),
42+
'ttl' => $this->getTTL(),
43+
'type' => $this->getType()->getName(),
44+
'target' => $this->getValue(),
45+
];
46+
}
3347
}

0 commit comments

Comments
 (0)