scanPaths = $scanPaths; foreach ($this->scanPaths as $path) { $this->recursiveScan($path); } return $this; } /** * Start the scan process * * @param string $dir A valid directory path where the scan will run * @param string[] $results Used for recursion, do not pass in value with calling * * @return self The scan check object with the results of the scan */ private function recursiveScan($dir, &$results = array()) { //Stop Recursion if Max search is reached if ($this->fileCount > $this->maxFiles || $this->dirCount > $this->maxDirs) { $this->limitReached = true; return $this; } $files = array_diff(@scandir($dir), array('..', '.')); if (is_array($files)) { foreach ($files as $key => $value) { $path = $dir . '/' . $value; //Files if (!is_dir($path)) { if (!is_readable($path)) { $results[] = $path; $this->unreadable[] = $path; } elseif ($this->isLink($path)) { $results[] = $path; $this->symLinks[] = $path; } else { $name = basename($path); $invalid_test = preg_match('/(\/|\*|\?|\>|\<|\:|\\|\|)/', $name) || trim($name) == '' || (strrpos($name, '.') == strlen($name) - 1 && substr($name, -1) == '.') || preg_match('/[^\x20-\x7f]/', $name); if ($invalid_test) { if (!SnapUtil::isPHP7Plus() && SnapOS::isWindows()) { $this->nameTestFiles[] = utf8_decode($path); } else { $this->nameTestFiles[] = $path; } } } $this->fileCount++; } elseif ($value != "." && $value != "..") { //Dirs if (!$this->isLink($path) && $this->recursion) { $this->recursiveScan($path, $results); } if (!is_readable($path)) { $results[] = $path; $this->unreadable[] = $path; } elseif ($this->isLink($path)) { $results[] = $path; $this->symLinks[] = $path; } else { $invalid_test = strlen($path) > 244 || trim($path) == '' || preg_match('/[^\x20-\x7f]/', $path); if ($invalid_test) { if (!SnapUtil::isPHP7Plus() && SnapOS::isWindows()) { $this->nameTestDirs[] = utf8_decode($path); } else { $this->nameTestDirs[] = $path; } } } $this->dirCount++; } } } return $this; } /** * Separation logic for supporting how different operating systems work * * @param string $target A valid file path * * @return bool Is the target a sym link */ private function isLink($target) { //Currently Windows does not support sym-link detection if (SnapOS::isWindows()) { return false; } elseif (is_link($target)) { return true; } return false; } }