function PathMatcher::matchPath

Same name in other branches
  1. 9 core/lib/Drupal/Core/Path/PathMatcher.php \Drupal\Core\Path\PathMatcher::matchPath()
  2. 8.9.x core/lib/Drupal/Core/Path/PathMatcher.php \Drupal\Core\Path\PathMatcher::matchPath()
  3. 11.x core/lib/Drupal/Core/Path/PathMatcher.php \Drupal\Core\Path\PathMatcher::matchPath()

File

core/lib/Drupal/Core/Path/PathMatcher.php, line 65

Class

PathMatcher
Provides a path matcher.

Namespace

Drupal\Core\Path

Code

public function matchPath($path, $patterns) {
    if (!isset($this->regexes[$patterns])) {
        // Convert path settings to a regular expression.
        $to_replace = [
            // Replace newlines with a logical 'or'.
'/(\\r\\n?|\\n)/',
            // Quote asterisks.
'/\\\\\\*/',
            // Quote <front> keyword.
'/(^|\\|)\\\\<front\\\\>($|\\|)/',
        ];
        $replacements = [
            '|',
            '.*',
            '\\1' . preg_quote($this->getFrontPagePath(), '/') . '\\2',
        ];
        $patterns_quoted = preg_quote($patterns, '/');
        $this->regexes[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';
    }
    return (bool) preg_match($this->regexes[$patterns], $path);
}

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