Browse Source

add custom provider support

main 1.4.0
yggverse 9 months ago
parent
commit
a57028f609
  1. 2
      README.md
  2. 39
      src/Dig.php

2
README.md

@ -40,7 +40,7 @@ var_dump( @@ -40,7 +40,7 @@ var_dump(
```
var_dump(
\Yggverse\Net\Dig::records('yo.index', ['A', 'AAAA'])
\Yggverse\Net\Dig::records('yo.index', ['A', 'AAAA'], &$result = [], &$error = [], $provider = null)
);
```

39
src/Dig.php

@ -17,32 +17,59 @@ class Dig @@ -17,32 +17,59 @@ class Dig
];
}
public static function isProvider(mixed $value): bool
{
return
(
is_string($value) &&
false !== filter_var($value, FILTER_VALIDATE_IP)
);
}
public static function isHostName(mixed $value, array $find = ['_'], array $replace = []): bool
{
return is_string($value) && false !== filter_var(str_replace($find, $replace, $value), FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
return (
is_string($value) &&
false !== filter_var(str_replace($find, $replace, $value), FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
);
}
public static function isRecord(mixed $value): bool
{
return is_string($value) && isset(self::_records()[$value]);
return
(
is_string($value) &&
isset(self::_records()[$value])
);
}
public static function isRecordValue(mixed $record, mixed $value): bool
{
return is_string($record) &&
return
(
is_string($record) &&
is_string($value) &&
isset(self::_records()[$record]) && self::_records()[$record]($value);
isset(self::_records()[$record]) && self::_records()[$record]($value)
);
}
public static function records(string $hostname, array $records, array &$result = [], array &$error = []): array
public static function records(string $hostname, array $records, array &$result = [], array &$error = [], ?string $provider = null): array
{
if (self::isProvider($provider))
{
$provider = sprintf(
'@%s',
$provider
);
}
if (self::isHostName($hostname))
{
foreach ($records as $record)
{
if (self::isRecord($record))
{
if ($values = exec(sprintf('dig %s %s +short', $record, $hostname)))
if ($values = exec(sprintf('dig %s %s %s +short', (string) $provider, (string) $record, (string) $hostname)))
{
foreach (explode(PHP_EOL, $values) as $value)
{

Loading…
Cancel
Save