Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Path/PathMatcher.php \Drupal\Core\Path\PathMatcher::matchPath()
  2. 9 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);
}