true); $patternIsValid = preg_match($ignoreRegex, '') !== false; restore_error_handler(); if (!$patternIsValid) { throw new InvalidArgumentException("The ignore pattern '$ignoreRegex' is not a valid regular expression."); } $finder = (new Finder()) ->files() ->ignoreDotFiles(false) ->ignoreVCS(false) ->ignoreUnreadableDirs() ->exclude($excludedDirectories) ->in($basePath); $hashes = []; foreach ($finder as $file) { $relativePath = str_replace(DIRECTORY_SEPARATOR, '/', $file->getRelativePathname()); if (preg_match($ignoreRegex, '/' . $relativePath) === 1) { if ($debug !== null) { $debug('[ Ignored] ' . $file->getFilename()); } continue; } $md5 = @md5_file($file->getPathname()); if ($debug !== null) { $debug("[$md5] " . $file->getFilename()); } $hashes[$relativePath] = $md5; } uksort($hashes, self::compareManifestPaths(...)); return $hashes; } private static function compareManifestPaths(string $left, string $right) : int { $leftParts = explode('/', $left); $rightParts = explode('/', $right); $partCount = min(count($leftParts), count($rightParts)); for ($index = 0; $index < $partCount; $index++) { $leftIsFile = $index === count($leftParts) - 1; $rightIsFile = $index === count($rightParts) - 1; if ($leftIsFile !== $rightIsFile) { return $leftIsFile ? -1 : 1; } $comparison = strcmp($leftParts[$index], $rightParts[$index]); if ($comparison !== 0) { return $comparison; } } return count($leftParts) <=> count($rightParts); } }