Debian Codegraph @

lib/3rdParty/composer/symfony/http-client/Internal/AmpResolverV5.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
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 * Handles local overrides for the DNS resolver.
21 *
22 * @author Nicolas Grekas <[email protected]>
23 *
24 * @internal
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 }