CoreFiles by mySites.guru
AmpResolver.php52 lines, 1,286 bytes, from Joomla_5.2.2-Stable-Full_Package.zip
Raw History Compare with 5.2.1
md5
72c6988076b76342683465ddfcf3fa69
sha1
42173c1533042d3bbcf126457d71e9add52102c4
sha256
53f70bb4ac7bf39ca2798caa25e0959a1f64494017aeb29bc6abf8cd54a808a3
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * 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;
use Amp\Dns\Record;
use Amp\Promise;
use Amp\Success;

/**
 * Handles local overrides for the DNS resolver.
 *
 * @author Nicolas Grekas <[email protected]>
 *
 * @internal
 */
class AmpResolver implements Dns\Resolver
{
    private array $dnsMap;

    public function __construct(array &$dnsMap)
    {
        $this->dnsMap = &$dnsMap;
    }

    public function resolve(string $name, ?int $typeRestriction = null): Promise
    {
        if (!isset($this->dnsMap[$name]) || !\in_array($typeRestriction, [Record::A, null], true)) {
            return Dns\resolver()->resolve($name, $typeRestriction);
        }

        return new Success([new Record($this->dnsMap[$name], Record::A, null)]);
    }

    public function query(string $name, int $type): Promise
    {
        if (!isset($this->dnsMap[$name]) || Record::A !== $type) {
            return Dns\resolver()->query($name, $type);
        }

        return new Success([new Record($this->dnsMap[$name], Record::A, null)]);
    }
}

The same content is in 39 releases, Joomla 5.1.0-beta1 to 5.3.0-alpha3. See them all, or every version of this file.