You are here

public function FilebrowserValidator::matchPath in Filebrowser 8.2

Same name and namespace in other branches
  1. 3.x src/Services/FilebrowserValidator.php \Drupal\filebrowser\Services\FilebrowserValidator::matchPath()

Helper function to match a pattern on the path

Parameters

string $path to process:

array $patterns to search (separated by cr):

Return value

TRUE if at least one pattern is found

2 calls to FilebrowserValidator::matchPath()
FilebrowserValidator::blackListed in src/Services/FilebrowserValidator.php
FilebrowserValidator::whiteListed in src/Services/FilebrowserValidator.php

File

src/Services/FilebrowserValidator.php, line 22

Class

FilebrowserValidator

Namespace

Drupal\filebrowser\Services

Code

public function matchPath($path, $patterns) {
  static $regexps = NULL;

  //var_dump($path);
  if (!isset($regexps[$patterns])) {
    $regexps[$patterns] = '/^(' . preg_replace([
      '/(\\r\\n?|\\n)/',
      '/\\\\\\*/',
    ], [
      '|',
      '.*',
    ], preg_quote($patterns, '/')) . ')$/i';
  }
  $result = preg_match($regexps[$patterns], $this
    ->safeBaseName($path)) == 1;
  return $result;
}