You are here

public function Domain301RedirectManager::checkDomain in Domain 301 Redirect 8

Checks if a domain actually points to this site.

Parameters

string $domain: The domain to be checked.

Return value

bool Returns TRUE if the domain passes the check. FALSE otherwise.

Overrides Domain301RedirectManagerInterface::checkDomain

File

src/Domain301RedirectManager.php, line 70

Class

Domain301RedirectManager
Defines an Domain301RedirectManager service.

Namespace

Drupal\domain_301_redirect

Code

public function checkDomain($domain) {
  if (!empty($domain)) {
    $retries = $this->config
      ->get('domain_check_retries');

    // Try to contact the redirect domain, if this fails, retry N times after
    // a pause.
    $uri = $this
      ->getRedirectCheckUrl($domain)
      ->toString();
    for ($i = 1; $i <= $retries; $i++) {
      try {
        $response = $this->client
          ->get($uri);
        if ($response
          ->getStatusCode() == 200) {
          return TRUE;
        }
      } catch (RequestException $e) {
      }

      // Pause between retries.
      if ($i < $retries) {
        sleep(10);
      }
    }
  }
  return FALSE;
}