function Endpoint::matchUrl

Same name and namespace in other branches
  1. 9 core/modules/media/src/OEmbed/Endpoint.php \Drupal\media\OEmbed\Endpoint::matchUrl()
  2. 10 core/modules/media/src/OEmbed/Endpoint.php \Drupal\media\OEmbed\Endpoint::matchUrl()
  3. 11.x core/modules/media/src/OEmbed/Endpoint.php \Drupal\media\OEmbed\Endpoint::matchUrl()

Tries to match a URL against the endpoint schemes.

Parameters

string $url: Media item URL.

Return value

bool TRUE if the URL matches against the endpoint schemes, otherwise FALSE.

File

core/modules/media/src/OEmbed/Endpoint.php, line 151

Class

Endpoint
Value object for oEmbed provider endpoints.

Namespace

Drupal\media\OEmbed

Code

public function matchUrl($url) {
    foreach ($this->getSchemes() as $scheme) {
        // Convert scheme into a valid regular expression.
        $regexp = str_replace([
            '.',
            '*',
        ], [
            '\\.',
            '.*',
        ], $scheme);
        if (preg_match("|^{$regexp}\$|", $url)) {
            return TRUE;
        }
    }
    return FALSE;
}

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