diff --git a/README.md b/README.md index 8986e64..a04c41e 100644 --- a/README.md +++ b/README.md @@ -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(); }); ``` diff --git a/examples/custom-config.php b/examples/custom-config.php index 9e3d2a9..43e75cd 100644 --- a/examples/custom-config.php +++ b/examples/custom-config.php @@ -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"; diff --git a/src/functions.php b/src/functions.php index e81f9b2..06ea9c2 100644 --- a/src/functions.php +++ b/src/functions.php @@ -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); } /** diff --git a/test/IntegrationTest.php b/test/IntegrationTest.php index 2cda9c1..f7bace8 100644 --- a/test/IntegrationTest.php +++ b/test/IntegrationTest.php @@ -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.'); }