dns-over-https/examples/_bootstrap.php

26 lines
756 B
PHP
Raw Normal View History

2022-12-18 14:37:59 +01:00
<?php declare(strict_types=1);
2019-06-10 19:32:28 +02:00
2023-01-12 15:49:35 +01:00
use Amp\Dns\DnsRecord;
2019-06-10 19:32:28 +02:00
require __DIR__ . "/../vendor/autoload.php";
2023-01-12 15:49:35 +01:00
/**
* @param array<DnsRecord> $records
*/
function pretty_print_records(string $queryName, array $records): void
2019-06-10 19:32:28 +02:00
{
2022-10-29 20:44:35 +02:00
print "---------- " . $queryName . " " . str_repeat("-", 55 - strlen($queryName)) . " TTL --\r\n";
2019-06-10 19:32:28 +02:00
$format = "%-10s %-56s %-5d\r\n";
foreach ($records as $record) {
2023-01-12 15:57:52 +01:00
print sprintf($format, DnsRecord::getName($record->getType()), $record->getValue(), $record->getTtl() ?? 0);
2019-06-10 19:32:28 +02:00
}
}
2023-01-12 15:49:35 +01:00
function pretty_print_error(string $queryName, \Throwable $error): void
2019-06-10 19:32:28 +02:00
{
2022-10-29 20:44:35 +02:00
print "-- " . $queryName . " " . str_repeat("-", 70 - strlen($queryName)) . "\r\n";
print get_class($error) . ": " . $error->getMessage() . "\r\n";
2019-06-10 19:32:28 +02:00
}