HM\BackUpWordPress\Excludes::get_excludes_for_regex PHP Метод

get_excludes_for_regex() публичный Метод

The primary difference being that any wildcard (*) rules are converted to the regex fragment [\s\S]*?.
public get_excludes_for_regex ( ) : array
Результат array The array of exclude rules.
    public function get_excludes_for_regex()
    {
        $excludes = $this->get_excludes();
        // Prepare the exclude rules.
        foreach ($excludes as &$exclude) {
            if (strpos($exclude, '*') !== false) {
                // Escape slashes.
                $exclude = str_replace('/', '\\/', $exclude);
                // Convert WildCards to regex.
                $exclude = str_replace('*', '[\\s\\S]*?', $exclude);
                // Wrap in slashes.
                $exclude = '/' . $exclude . '/';
            }
        }
        return $excludes;
    }

Usage Example

 /**
  * Returns a Finder instance for the files that will be included in the
  * backup.
  *
  * By default we ignore unreadable files and directories as well as, common
  * version control folders / files, "Dot" files and anything matching the
  * exclude rules.
  *
  * @uses Finder
  * @return SplFileInfo[] The array of all files to be included
  */
 public function get_files()
 {
     $finder = new Finder();
     $finder->followLinks();
     // defaults to true
     $finder->ignoreDotFiles(false);
     $finder->ignoreVCS(true);
     $finder->ignoreUnreadableDirs(true);
     // Skip unreadable files too
     $finder->filter(function (\SplFileInfo $file) {
         if (!$file->isReadable()) {
             return false;
         }
     });
     // Finder expects exclude rules to be in a regex format
     $exclude_rules = $this->excludes->get_excludes_for_regex();
     // Skips folders/files that match default exclude patterns
     foreach ($exclude_rules as $exclude) {
         $finder->notPath($exclude);
     }
     return $finder->in(Path::get_root());
 }