function AnnounceFetcher::validateUrl

Same name in other branches
  1. 11.x core/modules/announcements_feed/src/AnnounceFetcher.php \Drupal\announcements_feed\AnnounceFetcher::validateUrl()

Check whether a link is controlled by D.O.

Parameters

string $url: URL to check.

Return value

bool Return True if the URL is controlled by the D.O.

1 call to AnnounceFetcher::validateUrl()
AnnounceFetcher::fetch in core/modules/announcements_feed/src/AnnounceFetcher.php
Fetches the feed either from a local cache or fresh remotely.

File

core/modules/announcements_feed/src/AnnounceFetcher.php, line 95

Class

AnnounceFetcher
Service to fetch announcements from the external feed.

Namespace

Drupal\announcements_feed

Code

public static function validateUrl(string $url) : bool {
    if (empty($url)) {
        return FALSE;
    }
    $host = parse_url($url, PHP_URL_HOST);
    // First character can only be a letter or a digit.
    // @see https://www.rfc-editor.org/rfc/rfc1123#page-13
    return $host && preg_match('/^([a-zA-Z0-9][a-zA-Z0-9\\-_]*\\.)?drupal\\.org$/', $host);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.