diff --git a/README.md b/README.md index 9956b8b..bd6e012 100644 --- a/README.md +++ b/README.md @@ -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) ); ``` diff --git a/src/Dig.php b/src/Dig.php index 7323f0c..c7d221d 100644 --- a/src/Dig.php +++ b/src/Dig.php @@ -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) && - is_string($value) && - isset(self::_records()[$record]) && self::_records()[$record]($value); + return + ( + is_string($record) && + is_string($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) {