| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\HttpClient\Internal; |
| 13 |
|
| 14 |
use Amp\Cancellation; |
| 15 |
use Amp\Dns; |
| 16 |
use Amp\Dns\DnsRecord; |
| 17 |
use Amp\Dns\DnsResolver; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
class AmpResolverV5 implements DnsResolver |
| 27 |
{ |
| 28 |
public function __construct( |
| 29 |
private array &$dnsMap, |
| 30 |
) { |
| 31 |
} |
| 32 |
|
| 33 |
public function resolve(string $name, ?int $typeRestriction = null, ?Cancellation $cancellation = null): array |
| 34 |
{ |
| 35 |
$recordType = DnsRecord::A; |
| 36 |
$ip = $this->dnsMap[$name] ?? null; |
| 37 |
|
| 38 |
if (null !== $ip && str_contains($ip, ':')) { |
| 39 |
$recordType = DnsRecord::AAAA; |
| 40 |
} |
| 41 |
|
| 42 |
if (null === $ip || $recordType !== ($typeRestriction ?? $recordType)) { |
| 43 |
return Dns\resolve($name, $typeRestriction, $cancellation); |
| 44 |
} |
| 45 |
|
| 46 |
return [new DnsRecord($ip, $recordType, null)]; |
| 47 |
} |
| 48 |
|
| 49 |
public function query(string $name, int $type, ?Cancellation $cancellation = null): array |
| 50 |
{ |
| 51 |
$recordType = DnsRecord::A; |
| 52 |
$ip = $this->dnsMap[$name] ?? null; |
| 53 |
|
| 54 |
if (null !== $ip && str_contains($ip, ':')) { |
| 55 |
$recordType = DnsRecord::AAAA; |
| 56 |
} |
| 57 |
|
| 58 |
if (null !== $ip || $recordType !== $type) { |
| 59 |
return Dns\resolve($name, $type, $cancellation); |
| 60 |
} |
| 61 |
|
| 62 |
return [new DnsRecord($ip, $recordType, null)]; |
| 63 |
} |
| 64 |
} |