excludes = $excludes; $this->pattern = $pattern; $this->flags = $flags; } /** * @param string $startDir The directory to scan, defaults to Tiki root dir * * @return array An array of all files matched, or an empty array if no files matched */ public function process(string $startDir = ''): array { $files = glob($startDir . $this->pattern, $this->flags); foreach ($files as $key => $fileName) { foreach ($this->excludes as $exclude) { if (strpos($fileName, $exclude)) { unset($files[$key]); break; } } } foreach (glob($startDir . '*', GLOB_ONLYDIR | GLOB_NOSORT | GLOB_MARK) as $dir) { // lets ignore hidden directories (and the .. and . files) if (strpos($dir, '.') === 0 && is_dir($dir)) { break; } /** If the directory has not been excluded from processing */ $include = true; foreach ($this->excludes as $exclude) { if (strpos($dir, $exclude) !== false) { $include = false; break; } } if ($include) { $files = array_merge($files, $this->process($dir)); } } return $files; } }