Files
code-bang/backend/vendor/symfony/http-client/Internal/AmpResolverV4.php
T

63 lines
1.5 KiB
PHP
Raw Normal View History

2026-09-22 16:43:47 +08:00
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpClient\Internal;
use Amp\Dns;
2026-10-16 18:13:09 +08:00
use Amp\Dns\Record;
use Amp\Promise;
use Amp\Success;
2026-09-22 16:43:47 +08:00
/**
* Handles local overrides for the DNS resolver.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
2026-10-16 18:13:09 +08:00
class AmpResolverV4 implements Dns\Resolver
2026-09-22 16:43:47 +08:00
{
public function __construct(
private array &$dnsMap,
) {
}
2026-10-16 18:13:09 +08:00
public function resolve(string $name, ?int $typeRestriction = null): Promise
2026-09-22 16:43:47 +08:00
{
2026-10-16 18:13:09 +08:00
$recordType = Record::A;
2026-09-22 16:43:47 +08:00
$ip = $this->dnsMap[$name] ?? null;
if (null !== $ip && str_contains($ip, ':')) {
2026-10-16 18:13:09 +08:00
$recordType = Record::AAAA;
2026-09-22 16:43:47 +08:00
}
if (null === $ip || $recordType !== ($typeRestriction ?? $recordType)) {
2026-10-16 18:13:09 +08:00
return Dns\resolver()->resolve($name, $typeRestriction);
2026-09-22 16:43:47 +08:00
}
2026-10-16 18:13:09 +08:00
return new Success([new Record($ip, $recordType, null)]);
2026-09-22 16:43:47 +08:00
}
2026-10-16 18:13:09 +08:00
public function query(string $name, int $type): Promise
2026-09-22 16:43:47 +08:00
{
2026-10-16 18:13:09 +08:00
$recordType = Record::A;
2026-09-22 16:43:47 +08:00
$ip = $this->dnsMap[$name] ?? null;
if (null !== $ip && str_contains($ip, ':')) {
2026-10-16 18:13:09 +08:00
$recordType = Record::AAAA;
2026-09-22 16:43:47 +08:00
}
2026-10-16 18:13:09 +08:00
if (null === $ip || $recordType !== $type) {
return Dns\resolver()->query($name, $type);
2026-09-22 16:43:47 +08:00
}
2026-10-16 18:13:09 +08:00
return new Success([new Record($ip, $recordType, null)]);
2026-09-22 16:43:47 +08:00
}
}