-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathTypes.php
56 lines (46 loc) · 1.16 KB
/
Types.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Spatie\Dns\Support;
class Types
{
public static function getTypes()
{
$dnsTypes = [
DNS_A => 'A',
DNS_AAAA => 'AAAA',
DNS_CNAME => 'CNAME',
DNS_NS => 'NS',
DNS_PTR => 'PTR',
DNS_SOA => 'SOA',
DNS_MX => 'MX',
DNS_SRV => 'SRV',
DNS_TXT => 'TXT',
// DNS_NAPTR => 'NAPTR',
];
//@see https://bugs.php.net/bug.php?id=75909
if (defined('DNS_CAA')) {
$dnsTypes[DNS_CAA] = 'CAA';
}
return $dnsTypes;
}
public function toNames(int $flags): array
{
$types = [];
foreach (static::getTypes() as $flag => $type) {
if ($flags & $flag) {
$types[$flag] = $type;
}
}
return $types;
}
public function toFlags(array $types): int
{
$flags = 0;
foreach ($types as $type) {
$flag = array_search(mb_strtoupper($type), static::getTypes());
if ($flag !== false) {
$flags = $flags | $flag;
}
}
return $flags;
}
}