PathMatcher::matchPath

public PathMatcher::matchPath($path, $patterns)

Checks if a path matches any pattern in a set of patterns.

Parameters

string $path: The path to match.

string $patterns: A set of patterns separated by a newline.

Return value

bool TRUE if the path matches a pattern, FALSE otherwise.

Overrides PathMatcherInterface::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 = array(
      // Replace newlines with a logical 'or'.
      '/(\r\n?|\n)/',
      // Quote asterisks.
      '/\\\\\*/',
      // Quote <front> keyword.
      '/(^|\|)\\\\<front\\\\>($|\|)/',
    );
    $replacements = array(
      '|',
      '.*',
      '\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);
}
doc_Drupal
2016-10-29 09:33:27
Comments
Leave a Comment

Please login to continue.