You are here

class CheckDnsService in Check DNS 8

Defines the CheckDns service.

Hierarchy

Expanded class hierarchy of CheckDnsService

1 string reference to 'CheckDnsService'
check_dns.services.yml in ./check_dns.services.yml
check_dns.services.yml
1 service uses CheckDnsService
check_dns.service in ./check_dns.services.yml
Drupal\check_dns\CheckDnsService

File

src/CheckDnsService.php, line 8

Namespace

Drupal\check_dns
View source
class CheckDnsService {

  /**
   * Constructs a new CheckDnsService.
   */
  public function __construct() {
  }

  /**
   * Validate email id and its DNS record.
   *
   * @param string $mail
   *   A mail to check.
   *
   * @return bool
   *   TRUE if email is valid and any records are found, FALSE otherwise.
   */
  public function validateEmail($mail) {

    // Validate e-mail.
    if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
      $mail = explode('@', $mail);
      return $this
        ->validateHost(end($mail));
    }
    else {
      return FALSE;
    }
  }

  /**
   * Validate whether a domain name exists or not.
   *
   * @param string $host
   *   A host to check.
   *
   * @return bool
   *   TRUE if any records are found, FALSE otherwise.
   */
  public function validateHost(string $host) {

    // Check the DNS records corresponding to the hostname or IP address.
    $result = dns_check_record($host);
    return $result;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CheckDnsService::validateEmail public function Validate email id and its DNS record.
CheckDnsService::validateHost public function Validate whether a domain name exists or not.
CheckDnsService::__construct public function Constructs a new CheckDnsService.