CoreFiles by mySites.guru
AmpResolverV4.php62 lines, 1,545 bytes, from Joomla_6.0.3-Stable-Full_Package.zip
Raw History Compare with 6.0.2
md5
aef588a4b202bef3358f7aa07100f770
sha1
19bcc4733b34a3deca2a4b38bb27c60b5114833e
sha256
ffabde6c428c96bc8ed20d63b506e669c837147b5a0142cd9d29c97d15287484
<?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 AmpResolverV4 implements Dns\Resolver
{
    public function __construct(
        private array &$dnsMap,
    ) {
    }

    public function resolve(string $name, ?int $typeRestriction = null): Promise
    {
        $recordType = Record::A;
        $ip = $this->dnsMap[$name] ?? null;

        if (null !== $ip && str_contains($ip, ':')) {
            $recordType = Record::AAAA;
        }
        if (null === $ip || $recordType !== ($typeRestriction ?? $recordType)) {
            return Dns\resolver()->resolve($name, $typeRestriction);
        }

        return new Success([new Record($ip, $recordType, null)]);
    }

    public function query(string $name, int $type): Promise
    {
        $recordType = Record::A;
        $ip = $this->dnsMap[$name] ?? null;

        if (null !== $ip && str_contains($ip, ':')) {
            $recordType = Record::AAAA;
        }
        if (null === $ip || $recordType !== $type) {
            return Dns\resolver()->query($name, $type);
        }

        return new Success([new Record($ip, $recordType, null)]);
    }
}

The same content is in 49 releases, Joomla 6.0.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.