1
0
mirror of https://github.com/danog/dns.git synced 2024-11-26 20:14:51 +01:00
dns/lib/functions.php

55 lines
1.1 KiB
PHP
Raw Permalink Normal View History

<?php
2015-07-28 03:53:44 +02:00
namespace Amp\Dns;
2016-08-24 06:14:10 +02:00
2017-06-15 22:06:50 +02:00
use Amp\Loop;
use Amp\Promise;
2016-08-02 23:57:40 +02:00
const LOOP_STATE_IDENTIFIER = Resolver::class;
2015-07-28 03:53:44 +02:00
/**
2017-06-17 10:49:54 +02:00
* Retrieve the application-wide dns resolver instance.
*
2016-08-02 23:57:40 +02:00
* @param \Amp\Dns\Resolver $resolver Optionally specify a new default dns resolver instance
*
* @return \Amp\Dns\Resolver Returns the application-wide dns resolver instance
*/
2016-08-24 06:14:10 +02:00
function resolver(Resolver $resolver = null): Resolver {
2016-08-02 23:57:40 +02:00
if ($resolver === null) {
2016-08-12 17:51:40 +02:00
$resolver = Loop::getState(LOOP_STATE_IDENTIFIER);
2017-06-15 22:06:50 +02:00
2016-08-02 23:57:40 +02:00
if ($resolver) {
return $resolver;
}
$resolver = driver();
}
2017-06-15 22:06:50 +02:00
2016-08-12 17:51:40 +02:00
Loop::setState(LOOP_STATE_IDENTIFIER, $resolver);
2017-06-15 22:06:50 +02:00
2016-08-02 23:57:40 +02:00
return $resolver;
}
2017-06-15 22:06:50 +02:00
/**
2017-06-17 10:49:54 +02:00
* Create a new dns resolver best-suited for the current environment.
*
* @return \Amp\Dns\Resolver
*/
2016-08-24 06:14:10 +02:00
function driver(): Resolver {
2017-06-23 13:14:51 +02:00
return new BasicResolver;
}
2015-08-02 04:18:44 +02:00
/**
* @see Resolver::resolve()
2015-08-02 04:18:44 +02:00
*/
function resolve(string $name, int $typeRestriction = null): Promise {
return resolver()->resolve($name, $typeRestriction);
}
2017-06-15 22:06:50 +02:00
2015-09-18 15:09:28 +02:00
/**
* @see Resolver::query()
2015-09-18 15:09:28 +02:00
*/
function query(string $name, int $type): Promise {
2017-06-23 01:02:07 +02:00
return resolver()->query($name, $type);
2017-01-25 16:36:19 +01:00
}