mirror of
https://github.com/danog/dns.git
synced 2025-01-22 13:31:12 +01:00
Rename resolver() to dnsResolver()
This commit is contained in:
parent
9f05c059f1
commit
f2098c773b
@ -69,7 +69,7 @@ The `Rfc1035StubResolver` (which is the default resolver shipping with that pack
|
||||
|
||||
```php
|
||||
EventLoop::repeat(600, function () use ($resolver) {
|
||||
Amp\Dns\resolver()->reloadConfig();
|
||||
Amp\Dns\dnsResolver()->reloadConfig();
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -16,7 +16,7 @@ $customConfigLoader = new class implements Dns\DnsConfigLoader {
|
||||
}
|
||||
};
|
||||
|
||||
Dns\resolver(new Dns\Rfc1035StubDnsResolver(null, $customConfigLoader));
|
||||
Dns\dnsResolver(new Dns\Rfc1035StubDnsResolver(null, $customConfigLoader));
|
||||
|
||||
$hostname = $argv[1] ?? "amphp.org";
|
||||
|
||||
|
@ -5,27 +5,27 @@ namespace Amp\Dns;
|
||||
use Revolt\EventLoop;
|
||||
|
||||
/**
|
||||
* Retrieve the application-wide dns resolver instance.
|
||||
* Retrieve the application-wide DNS resolver instance.
|
||||
*
|
||||
* @param DnsResolver|null $resolver Optionally specify a new default dns resolver instance
|
||||
* @param DnsResolver|null $dnsResolver Optionally specify a new default DNS resolver instance
|
||||
*
|
||||
* @return DnsResolver Returns the application-wide dns resolver instance
|
||||
* @return DnsResolver Returns the application-wide DNS resolver instance
|
||||
*/
|
||||
function resolver(DnsResolver $resolver = null): DnsResolver
|
||||
function dnsResolver(DnsResolver $dnsResolver = null): DnsResolver
|
||||
{
|
||||
static $map;
|
||||
$map ??= new \WeakMap();
|
||||
$driver = EventLoop::getDriver();
|
||||
|
||||
if ($resolver) {
|
||||
return $map[$driver] = $resolver;
|
||||
if ($dnsResolver) {
|
||||
return $map[$driver] = $dnsResolver;
|
||||
}
|
||||
|
||||
return $map[$driver] ??= createDefaultResolver();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new dns resolver best-suited for the current environment.
|
||||
* Create a new DNS resolver best-suited for the current environment.
|
||||
*/
|
||||
function createDefaultResolver(): DnsResolver
|
||||
{
|
||||
@ -39,7 +39,7 @@ function createDefaultResolver(): DnsResolver
|
||||
*/
|
||||
function resolve(string $name, int $typeRestriction = null): array
|
||||
{
|
||||
return resolver()->resolve($name, $typeRestriction);
|
||||
return dnsResolver()->resolve($name, $typeRestriction);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,7 +49,7 @@ function resolve(string $name, int $typeRestriction = null): array
|
||||
*/
|
||||
function query(string $name, int $type): array
|
||||
{
|
||||
return resolver()->query($name, $type);
|
||||
return dnsResolver()->query($name, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ class IntegrationTest extends AsyncTestCase
|
||||
public function testWorksAfterConfigReload(): void
|
||||
{
|
||||
Dns\query("google.com", DnsRecord::A);
|
||||
self::assertInstanceOf(Dns\DnsConfig::class, Dns\resolver()->reloadConfig());
|
||||
self::assertInstanceOf(Dns\DnsConfig::class, Dns\dnsResolver()->reloadConfig());
|
||||
self::assertIsArray(Dns\query("example.com", DnsRecord::A));
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ class IntegrationTest extends AsyncTestCase
|
||||
->method('loadConfig')
|
||||
->willReturn($config);
|
||||
|
||||
Dns\resolver(new Dns\Rfc1035StubDnsResolver(null, $configLoader));
|
||||
Dns\dnsResolver(new Dns\Rfc1035StubDnsResolver(null, $configLoader));
|
||||
$result = Dns\resolve('blog');
|
||||
|
||||
$record = $result[0];
|
||||
@ -111,7 +111,7 @@ class IntegrationTest extends AsyncTestCase
|
||||
->method('loadConfig')
|
||||
->willReturn($config);
|
||||
|
||||
Dns\resolver(new Dns\Rfc1035StubDnsResolver(null, $configLoader));
|
||||
Dns\dnsResolver(new Dns\Rfc1035StubDnsResolver(null, $configLoader));
|
||||
$this->expectException(DnsException::class);
|
||||
Dns\resolve('blog.');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user