You are here

private function FileExcludeFilter::compileExcludePatterns in Backup and Migrate 8.4

Convert an array of glob patterns to an array of regex patterns for file name exclusion.

Parameters

array $exclude: A list of patterns with glob wildcards

Return value

array A list of patterns as regular expressions

1 call to FileExcludeFilter::compileExcludePatterns()
FileExcludeFilter::beforeFileBackup in lib/backup_migrate_core/src/Filter/FileExcludeFilter.php
The 'beforeDBTableBackup' plugin op.

File

lib/backup_migrate_core/src/Filter/FileExcludeFilter.php, line 63

Class

FileExcludeFilter
Class FileExcludeFilter.

Namespace

BackupMigrate\Core\Filter

Code

private function compileExcludePatterns($exclude) {
  if ($this->patterns !== NULL) {
    return $this->patterns;
  }
  foreach ($exclude as $pattern) {

    // Convert Glob wildcards to a regex per http://php.net/manual/en/function.fnmatch.php#71725
    $this->patterns[] = "#^" . strtr(preg_quote($pattern, '#'), [
      '\\*' => '.*',
      '\\?' => '.',
      '\\[' => '[',
      '\\]' => ']',
    ]) . "\$#i";
  }
  return $this->patterns;
}