self::purgeAll(), 'pagelinks' => $pagelinks ? self::purgePagelinks() : null, 'thumbs' => $thumbs ? self::purgeThumbs() : null, ]; } /** * Remove all files and subdirectories inside a directory * without removing the directory itself. * * @param string $directory * @param string[] $skip Entry names (not paths) to leave untouched. * @return int Number of removed files/directories. */ public static function removeDirectoryEntries(string $directory, array $skip = []): int { if ($directory === '' || !is_dir($directory) || !is_readable($directory)) { return 0; } $entries = @scandir($directory); if (!is_array($entries)) return 0; $removed = 0; foreach ($entries as $entry) { if ($entry === '.' || $entry === '..') continue; if ($skip !== [] && in_array($entry, $skip, true)) continue; $path = $directory . '/' . $entry; if (is_dir($path) && !is_link($path)) { $removed += self::removeDirectoryEntries($path); if (@rmdir($path)) { $removed++; } continue; } if ((is_file($path) || is_link($path)) && @unlink($path)) { $removed++; } } return $removed; } }