Conditions | 4 |
Paths | 8 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
32 | public static function createArchiveFromDirectory(string $directoryPath, string $name = null): string |
||
33 | { |
||
34 | if (empty($name)) { |
||
35 | $name = self::generateRandomNameOfArchive(); |
||
36 | } |
||
37 | |||
38 | $zip = new ZipArchive(); |
||
39 | $zip->open($name, ZipArchive::CREATE); |
||
40 | |||
41 | $fixer = new PathFixer($directoryPath); |
||
42 | |||
43 | foreach (FSHelper::getDirectories($directoryPath) as $dir) { |
||
44 | $zip->addEmptyDir($fixer->fix($dir->getPathname())); |
||
45 | } |
||
46 | |||
47 | foreach (FSHelper::getFiles($directoryPath) as $file) { |
||
48 | $zip->addFile($file->getPathname(), $fixer->fix($file->getPathname())); |
||
49 | } |
||
50 | |||
51 | $zip->close(); |
||
52 | |||
53 | return $name; |
||
54 | } |
||
56 |