Skip to content

Commit a57028f

Browse files
author
yggverse
committed
add custom provider support
1 parent 16f90cb commit a57028f

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var_dump(
4040

4141
```
4242
var_dump(
43-
\Yggverse\Net\Dig::records('yo.index', ['A', 'AAAA'])
43+
\Yggverse\Net\Dig::records('yo.index', ['A', 'AAAA'], &$result = [], &$error = [], $provider = null)
4444
);
4545
```
4646

src/Dig.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,59 @@ private static function _records(): array
1717
];
1818
}
1919

20+
public static function isProvider(mixed $value): bool
21+
{
22+
return
23+
(
24+
is_string($value) &&
25+
false !== filter_var($value, FILTER_VALIDATE_IP)
26+
);
27+
}
28+
2029
public static function isHostName(mixed $value, array $find = ['_'], array $replace = []): bool
2130
{
22-
return is_string($value) && false !== filter_var(str_replace($find, $replace, $value), FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
31+
return (
32+
is_string($value) &&
33+
false !== filter_var(str_replace($find, $replace, $value), FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
34+
);
2335
}
2436

2537
public static function isRecord(mixed $value): bool
2638
{
27-
return is_string($value) && isset(self::_records()[$value]);
39+
return
40+
(
41+
is_string($value) &&
42+
isset(self::_records()[$value])
43+
);
2844
}
2945

3046
public static function isRecordValue(mixed $record, mixed $value): bool
3147
{
32-
return is_string($record) &&
33-
is_string($value) &&
34-
isset(self::_records()[$record]) && self::_records()[$record]($value);
48+
return
49+
(
50+
is_string($record) &&
51+
is_string($value) &&
52+
isset(self::_records()[$record]) && self::_records()[$record]($value)
53+
);
3554
}
3655

37-
public static function records(string $hostname, array $records, array &$result = [], array &$error = []): array
56+
public static function records(string $hostname, array $records, array &$result = [], array &$error = [], ?string $provider = null): array
3857
{
58+
if (self::isProvider($provider))
59+
{
60+
$provider = sprintf(
61+
'@%s',
62+
$provider
63+
);
64+
}
65+
3966
if (self::isHostName($hostname))
4067
{
4168
foreach ($records as $record)
4269
{
4370
if (self::isRecord($record))
4471
{
45-
if ($values = exec(sprintf('dig %s %s +short', $record, $hostname)))
72+
if ($values = exec(sprintf('dig %s %s %s +short', (string) $provider, (string) $record, (string) $hostname)))
4673
{
4774
foreach (explode(PHP_EOL, $values) as $value)
4875
{

0 commit comments

Comments
 (0)