| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace React\Dns\Resolver;
|
|
|
4 |
|
|
|
5 |
interface ResolverInterface
|
|
|
6 |
{
|
|
|
7 |
/**
|
|
|
8 |
* Resolves the given $domain name to a single IPv4 address (type `A` query).
|
|
|
9 |
*
|
|
|
10 |
* ```php
|
|
|
11 |
* $resolver->resolve('reactphp.org')->then(function ($ip) {
|
|
|
12 |
* echo 'IP for reactphp.org is ' . $ip . PHP_EOL;
|
|
|
13 |
* });
|
|
|
14 |
* ```
|
|
|
15 |
*
|
|
|
16 |
* This is one of the main methods in this package. It sends a DNS query
|
|
|
17 |
* for the given $domain name to your DNS server and returns a single IP
|
|
|
18 |
* address on success.
|
|
|
19 |
*
|
|
|
20 |
* If the DNS server sends a DNS response message that contains more than
|
|
|
21 |
* one IP address for this query, it will randomly pick one of the IP
|
|
|
22 |
* addresses from the response. If you want the full list of IP addresses
|
|
|
23 |
* or want to send a different type of query, you should use the
|
|
|
24 |
* [`resolveAll()`](#resolveall) method instead.
|
|
|
25 |
*
|
|
|
26 |
* If the DNS server sends a DNS response message that indicates an error
|
|
|
27 |
* code, this method will reject with a `RecordNotFoundException`. Its
|
|
|
28 |
* message and code can be used to check for the response code.
|
|
|
29 |
*
|
|
|
30 |
* If the DNS communication fails and the server does not respond with a
|
|
|
31 |
* valid response message, this message will reject with an `Exception`.
|
|
|
32 |
*
|
|
|
33 |
* Pending DNS queries can be cancelled by cancelling its pending promise like so:
|
|
|
34 |
*
|
|
|
35 |
* ```php
|
|
|
36 |
* $promise = $resolver->resolve('reactphp.org');
|
|
|
37 |
*
|
|
|
38 |
* $promise->cancel();
|
|
|
39 |
* ```
|
|
|
40 |
*
|
|
|
41 |
* @param string $domain
|
|
|
42 |
* @return \React\Promise\PromiseInterface<string,\Exception>
|
|
|
43 |
* resolves with a single IP address on success or rejects with an Exception on error.
|
|
|
44 |
*/
|
|
|
45 |
public function resolve($domain);
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Resolves all record values for the given $domain name and query $type.
|
|
|
49 |
*
|
|
|
50 |
* ```php
|
|
|
51 |
* $resolver->resolveAll('reactphp.org', Message::TYPE_A)->then(function ($ips) {
|
|
|
52 |
* echo 'IPv4 addresses for reactphp.org ' . implode(', ', $ips) . PHP_EOL;
|
|
|
53 |
* });
|
|
|
54 |
*
|
|
|
55 |
* $resolver->resolveAll('reactphp.org', Message::TYPE_AAAA)->then(function ($ips) {
|
|
|
56 |
* echo 'IPv6 addresses for reactphp.org ' . implode(', ', $ips) . PHP_EOL;
|
|
|
57 |
* });
|
|
|
58 |
* ```
|
|
|
59 |
*
|
|
|
60 |
* This is one of the main methods in this package. It sends a DNS query
|
|
|
61 |
* for the given $domain name to your DNS server and returns a list with all
|
|
|
62 |
* record values on success.
|
|
|
63 |
*
|
|
|
64 |
* If the DNS server sends a DNS response message that contains one or more
|
|
|
65 |
* records for this query, it will return a list with all record values
|
|
|
66 |
* from the response. You can use the `Message::TYPE_*` constants to control
|
|
|
67 |
* which type of query will be sent. Note that this method always returns a
|
|
|
68 |
* list of record values, but each record value type depends on the query
|
|
|
69 |
* type. For example, it returns the IPv4 addresses for type `A` queries,
|
|
|
70 |
* the IPv6 addresses for type `AAAA` queries, the hostname for type `NS`,
|
|
|
71 |
* `CNAME` and `PTR` queries and structured data for other queries. See also
|
|
|
72 |
* the `Record` documentation for more details.
|
|
|
73 |
*
|
|
|
74 |
* If the DNS server sends a DNS response message that indicates an error
|
|
|
75 |
* code, this method will reject with a `RecordNotFoundException`. Its
|
|
|
76 |
* message and code can be used to check for the response code.
|
|
|
77 |
*
|
|
|
78 |
* If the DNS communication fails and the server does not respond with a
|
|
|
79 |
* valid response message, this message will reject with an `Exception`.
|
|
|
80 |
*
|
|
|
81 |
* Pending DNS queries can be cancelled by cancelling its pending promise like so:
|
|
|
82 |
*
|
|
|
83 |
* ```php
|
|
|
84 |
* $promise = $resolver->resolveAll('reactphp.org', Message::TYPE_AAAA);
|
|
|
85 |
*
|
|
|
86 |
* $promise->cancel();
|
|
|
87 |
* ```
|
|
|
88 |
*
|
|
|
89 |
* @param string $domain
|
|
|
90 |
* @return \React\Promise\PromiseInterface<array,\Exception>
|
|
|
91 |
* Resolves with all record values on success or rejects with an Exception on error.
|
|
|
92 |
*/
|
|
|
93 |
public function resolveAll($domain, $type);
|
|
|
94 |
}
|