Initial Commit

This commit is contained in:
David Stone
2024-11-30 18:24:12 -07:00
commit e8f7955c1c
5432 changed files with 1397750 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?php
namespace WP_Ultimo\Dependencies\Amp\Dns;
use WP_Ultimo\Dependencies\Amp\Failure;
use WP_Ultimo\Dependencies\Amp\Promise;
use WP_Ultimo\Dependencies\Amp\Success;
class BlockingFallbackResolver implements Resolver
{
public function resolve(string $name, int $typeRestriction = null) : Promise
{
if (!\in_array($typeRestriction, [Record::A, null], \true)) {
return new Failure(new DnsException("Query for '{$name}' failed, because loading the system's DNS configuration failed and querying records other than A records isn't supported in blocking fallback mode."));
}
return $this->query($name, Record::A);
}
public function query(string $name, int $type) : Promise
{
if ($type !== Record::A) {
return new Failure(new DnsException("Query for '{$name}' failed, because loading the system's DNS configuration failed and querying records other than A records isn't supported in blocking fallback mode."));
}
$result = \gethostbynamel($name);
if ($result === \false) {
return new Failure(new DnsException("Query for '{$name}' failed, because loading the system's DNS configuration failed and blocking fallback via gethostbynamel() failed, too."));
}
if ($result === []) {
return new Failure(new NoRecordException("No records returned for '{$name}' using blocking fallback mode."));
}
$records = [];
foreach ($result as $record) {
$records[] = new Record($record, Record::A, null);
}
return new Success($records);
}
}