Debian Codegraph @

lib/3rdParty/composer/symfony/http-client/Internal/AmpResolverV4.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\Dns;
15 use Amp\Dns\Record;
16 use Amp\Promise;
17 use Amp\Success;
18
19 /**
20 * Handles local overrides for the DNS resolver.
21 *
22 * @author Nicolas Grekas <[email protected]>
23 *
24 * @internal
25 */
26 class AmpResolverV4 implements Dns\Resolver
27 {
28 public function __construct(
29 private array &$dnsMap,
30 ) {
31 }
32
33 public function resolve(string $name, ?int $typeRestriction = null): Promise
34 {
35 $recordType = Record::A;
36 $ip = $this->dnsMap[$name] ?? null;
37
38 if (null !== $ip && str_contains($ip, ':')) {
39 $recordType = Record::AAAA;
40 }
41 if (null === $ip || $recordType !== ($typeRestriction ?? $recordType)) {
42 return Dns\resolver()->resolve($name, $typeRestriction);
43 }
44
45 return new Success([new Record($ip, $recordType, null)]);
46 }
47
48 public function query(string $name, int $type): Promise
49 {
50 $recordType = Record::A;
51 $ip = $this->dnsMap[$name] ?? null;
52
53 if (null !== $ip && str_contains($ip, ':')) {
54 $recordType = Record::AAAA;
55 }
56 if (null === $ip || $recordType !== $type) {
57 return Dns\resolver()->query($name, $type);
58 }
59
60 return new Success([new Record($ip, $recordType, null)]);
61 }
62 }