public static function excludeFromZip(ZipArchive $zipArchive, $pattern)
    {
        $i = 0;
        $exclusionCount = 0;

        while (($entryName = $zipArchive->getNameIndex($i)) || ($statIndex = $zipArchive->statIndex($i,ZipArchive::FL_UNCHANGED))) {
            if ($entryName) {
                // Not previously removed index.
                if (preg_match($pattern, $entryName) === 1 && $zipArchive->deleteIndex($i)) {
                    $exclusionCount++;
                }
            }

            $i++;
        }

        return $exclusionCount;
    }