ResolverInterface.php 3.9 KB

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